├── scripts └── jelly ├── .gitignore ├── utils ├── findhash ├── Makefile ├── findhash1.py └── findhash2.c ├── setup.py ├── ruff.toml ├── jelly ├── __init__.py ├── utils.py ├── __main__.py └── interpreter.py ├── LICENSE.txt └── README.md /scripts/jelly: -------------------------------------------------------------------------------- 1 | ../jelly/__main__.py -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | utils/findhash2 3 | *.pyc 4 | *jellylanguage.egg* 5 | .vscode -------------------------------------------------------------------------------- /utils/findhash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cd "$(dirname -- "$(readlink -e -- "$0")")" 4 | 5 | [[ -f findhash2 ]] || make -s 6 | 7 | (($# == 2)) && set "$@" $(seq "$2") 8 | 9 | python3 findhash1.py | ./findhash2 "$@" 10 | -------------------------------------------------------------------------------- /utils/Makefile: -------------------------------------------------------------------------------- 1 | CACHE_SIZE ?= 256 2 | NUM_THREADS ?= $(shell nproc) 3 | 4 | CFLAGS += -Wall -Wextra -O2 -pthread 5 | CFLAGS += -DNUM_THREADS=$(NUM_THREADS) -DCACHE_SIZE=$(CACHE_SIZE) 6 | 7 | findhash2: findhash2.c 8 | $(CC) $(CFLAGS) -o findhash2 findhash2.c 9 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | 3 | setup( 4 | name = "jellylanguage", 5 | version = "0.1.31", 6 | packages = [ 7 | "jelly" 8 | ], 9 | scripts = [ 10 | "scripts/jelly" 11 | ], 12 | install_requires = [ 13 | "sympy" 14 | ] 15 | ) 16 | -------------------------------------------------------------------------------- /ruff.toml: -------------------------------------------------------------------------------- 1 | select = ["E", "F", "B", "W", "ERA", "RET", "UP", "I", "N", "Q"] 2 | 3 | ignore = [ 4 | "E501", # Never enforce `E501` (line length violations). 5 | "E701", # Multiple statements on one line (colon) 6 | "E741", # Ambiguous variable name: `l` 7 | "B905", # `zip()` without an explicit `strict=` parameter 8 | ] 9 | -------------------------------------------------------------------------------- /utils/findhash1.py: -------------------------------------------------------------------------------- 1 | from hashlib import shake_256 2 | from sys import stdin, stdout 3 | 4 | from jelly import jellify, jelly_eval 5 | 6 | objects = stdin.read() 7 | 8 | try: 9 | objects = jellify(eval(objects)) 10 | except Exception: 11 | objects = jelly_eval(objects, []) 12 | 13 | for object in objects: 14 | stdout.buffer.write(shake_256(repr(object).encode("utf-8")).digest(512)) 15 | -------------------------------------------------------------------------------- /jelly/__init__.py: -------------------------------------------------------------------------------- 1 | from sys import stderr 2 | 3 | from .interpreter import * 4 | 5 | 6 | def main(code, args, end): 7 | for index in range(min(7, len(args))): 8 | atoms["³⁴⁵⁶⁷⁸⁹"[index]].call = lambda literal = args[index]: literal 9 | 10 | try: 11 | output(jelly_eval(code, args[:2]), end) 12 | except KeyboardInterrupt: 13 | if stderr.isatty(): 14 | sys.stderr.write("\n") 15 | return 130 16 | -------------------------------------------------------------------------------- /jelly/utils.py: -------------------------------------------------------------------------------- 1 | class attrdict(dict): 2 | def __init__(self, *args, **kwargs): 3 | dict.__init__(self, *args, **kwargs) 4 | self.__dict__ = self 5 | 6 | class LazyImport: 7 | def __init__(self, *args): 8 | self.args = args 9 | def __getattr__(self, attr): 10 | self.__dict__ = __import__(*self.args).__dict__ 11 | return self.__dict__[attr] 12 | 13 | def lazy_import(names): 14 | names = names.split() 15 | if len(names) == 1: 16 | return LazyImport(*names) 17 | return map(LazyImport, names) 18 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 DennisMitchell 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /jelly/__main__.py: -------------------------------------------------------------------------------- 1 | #!python3 2 | 3 | if __package__ == "": 4 | from os.path import dirname 5 | from sys import path 6 | 7 | path[0] = dirname(path[0]) 8 | 9 | from sys import argv 10 | 11 | from jelly import code_page, main, try_eval 12 | 13 | flag_utf8 = False 14 | end = "" 15 | 16 | usage = """Usage: 17 | 18 | jelly f [input] Reads the Jelly program stored in the 19 | specified file, using the Jelly code page. 20 | This option should be considered the default, 21 | but it exists solely for scoring purposes in 22 | code golf contests. 23 | 24 | jelly fu [input] Reads the Jelly program stored in the 25 | specified file, using the UTF-8 encoding. 26 | 27 | jelly e [input] Reads a Jelly program as a command line 28 | argument, using the Jelly code page. This 29 | requires setting the environment variable 30 | LANG (or your OS's equivalent) to en_US or 31 | compatible. 32 | 33 | jelly eu [input] Reads a Jelly program as a command line 34 | argument, using the UTF-8 encoding. This 35 | requires setting the environment variable 36 | LANG (or your OS's equivalent) to en_US.UTF8 37 | or compatible. 38 | 39 | Append an `n` to the flag list to append a trailing newline to the 40 | program's output. 41 | 42 | Visit http://github.com/DennisMitchell/jellylanguage for more information.""" 43 | 44 | if len(argv) < 3: 45 | raise SystemExit(usage) 46 | 47 | for char in argv[1]: 48 | if char == "f": 49 | flag_file = True 50 | elif char == "u": 51 | flag_utf8 = True 52 | elif char == "e": 53 | flag_file = False 54 | elif char == "n": 55 | end = "\n" 56 | 57 | compat = str.maketrans("\nụṿ", "¶§Ä") 58 | 59 | if flag_file: 60 | with open(argv[2], "rb") as file: 61 | code = file.read() 62 | if flag_utf8: 63 | code = "".join(char for char in code.decode("utf-8").translate(compat) if char in code_page) 64 | else: 65 | code = "".join(code_page[i] for i in code) 66 | else: 67 | code = argv[2] 68 | if flag_utf8: 69 | code = "".join(char for char in code.translate(compat) if char in code_page) 70 | else: 71 | code = "".join(code_page[ord(i)] for i in code) 72 | 73 | args = list(map(try_eval, argv[3:])) 74 | 75 | raise SystemExit(main(code, args, end)) 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #

🪼 Jellyfish 🪼

2 | 3 |

4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |

17 | 18 | Jellyfish is an extension of the [Jelly programming language](https://github.com/DennisMitchell/jellylanguage/) created by Dennis Mitchell. Please visit his [repo](https://github.com/DennisMitchell/jellylanguage/) for the original documentation. This repo will focus on fixes and extensions as well as additional documention when I think it may be helpful. 19 | 20 | Note that the primary way I interact with Jelly(fish) is through the Jello REPL. This allows you to write Jello keywords instead of Jelly atoms. It also visually diagrams the combinator trees that are implicitly created from the monadic, dyadic and multichains. You can find the [Jello repo here](https://github.com/codereport/jello/). 21 | 22 | ## Installing 23 | 24 | ```bash 25 | git clone -q https://github.com/codereport/jellyfish.git 26 | cd jellyfish 27 | pip3 install --upgrade --user . 28 | ``` 29 | 30 | ## Using 31 | 32 | The intended way of using Jellyfish is through the [Jello REPL](https://github.com/codereport/jello/). 33 | 34 | ## Differences 35 | 36 | ### Additions 37 | 38 | #### Atoms 39 | 40 | * `ṕ` (Q's `prior`) 41 | * `É` (dual to `odd?` i.e. `even?`) 42 | * `①` (`bits` aka `bit_count`, `pop_count` or `ones_count`) 43 | * `ḳ` (Uiua's `keep` and BQN/APL's `compress`/`replicate`) 44 | * `Ḿ` (Q's `maxs`) 45 | * `Ṕ` (Uiua's `partition` - we are calling it `part`) 46 | * `Ꝑ` (adding `part_by` - a generalization of `part`) 47 | * `≤` (less than equal to) 48 | * `≥` (greater than equal to) 49 | * `Œɠ` (previously `group_len`, this is a quick similar to `key`) 50 | * `Ď` (Q's `differ`) 51 | 52 | #### Chains 53 | 54 | * `D₂`: previously spelled `l f₁ : g₂ : r h₁` and now `g₂ f₁ h₁` 55 | 56 | ### Changes 57 | 58 | * `Ḣ`: `head` does not modify the underlying sequence 59 | * `Ṫ`: `last` does not modify the underlying sequence 60 | * `ÐṀ`: `max_by` returns a single value instead of list 61 | 62 | ### Deletions 63 | * `Œɠ`: delete `group_len`; it can now be spelled `len group` 64 | 65 | ### Fixes 66 | 67 | * `Ẓ`: isprime was broken, now fixed 68 | -------------------------------------------------------------------------------- /utils/findhash2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define ctz __builtin_ctzll 8 | 9 | typedef unsigned long long word_t; 10 | typedef unsigned __int128 dword_t; 11 | 12 | const int word_bits = 64; 13 | const int word_bytes = 8; 14 | const int cache_size = CACHE_SIZE; 15 | const int num_threads = NUM_THREADS; 16 | 17 | int num_buckets, num_integers; 18 | void *buckets_p, *cache_p, *jumps_p; 19 | 20 | volatile word_t score = (word_t) 0 - 1; 21 | pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; 22 | 23 | void find_hash(int num_buckets, int num_integers, int thread_num) 24 | { 25 | int *buckets = buckets_p; 26 | word_t (*cache)[num_integers] = cache_p; 27 | word_t (*jumps)[num_integers] = jumps_p; 28 | 29 | word_t states[num_integers]; 30 | memset(states, 0, sizeof(states)); 31 | int map[num_buckets]; 32 | word_t hash_num = 0; 33 | 34 | while(hash_num < score) 35 | { 36 | for(int i = thread_num; i < cache_size; i += num_threads) 37 | { 38 | memset(map, 0, sizeof(map)); 39 | int done = 1; 40 | 41 | for(int j = 0; j < num_integers; j++) 42 | { 43 | dword_t state = states[j] + cache[i][j]; 44 | word_t hash = state * num_buckets >> word_bits; 45 | 46 | if(map[hash] && map[hash] != buckets[j]) 47 | { 48 | done = 0; 49 | break; 50 | } 51 | 52 | map[hash] = buckets[j]; 53 | } 54 | 55 | if(done) 56 | { 57 | pthread_mutex_lock(&lock); 58 | hash_num += thread_num; 59 | score = hash_num < score ? hash_num : score; 60 | return; 61 | } 62 | 63 | hash_num += num_threads; 64 | } 65 | 66 | for(int j = 0, tz = ctz(hash_num); j < num_integers; j++) 67 | states[j] += jumps[tz][j]; 68 | } 69 | } 70 | 71 | void *wrapper(void *thread_num_p) 72 | { 73 | find_hash(num_buckets, num_integers, * (int *) thread_num_p); 74 | 75 | return NULL; 76 | } 77 | 78 | int main(int argc, char *argv[]) 79 | { 80 | assert(argc > 3); 81 | 82 | num_buckets = strtoul(argv[1], NULL, 0); 83 | assert(num_buckets > 0); 84 | 85 | num_integers = strtoul(argv[2], NULL, 0); 86 | assert(num_integers > 0 && num_integers == argc - 3); 87 | 88 | int buckets[num_integers]; 89 | buckets_p = buckets; 90 | 91 | for(int i = 0; i < num_integers; i++) 92 | { 93 | buckets[i] = strtoul(argv[3 + i], NULL, 0); 94 | assert(buckets[i] > 0 && buckets[i] <= num_buckets); 95 | } 96 | 97 | word_t integers[num_integers][word_bits]; 98 | assert(fread(integers, sizeof(integers), 1, stdin) == 1); 99 | 100 | word_t cache[cache_size][num_integers]; 101 | cache_p = cache; 102 | word_t jumps[word_bits][num_integers]; 103 | jumps_p = jumps; 104 | 105 | for(int i = 0; i < num_integers; i++) 106 | { 107 | cache[0][i] = 0; 108 | 109 | for(int j = 1; j < cache_size; j++) 110 | cache[j][i] = cache[j - 1][i] + integers[i][ctz(j)]; 111 | 112 | word_t offset = cache[cache_size - 1][i]; 113 | 114 | for(int j = 0; j < word_bits; j++) 115 | jumps[j][i] = integers[i][j] + offset; 116 | } 117 | 118 | pthread_t thread_id[num_threads]; 119 | int thread_nums[num_threads]; 120 | 121 | for(int i = 0; i < num_threads; i++) 122 | { 123 | thread_nums[i] = i; 124 | pthread_create(&thread_id[i], NULL, wrapper, &thread_nums[i]); 125 | } 126 | 127 | for(int i = 0; i < num_threads; i++) 128 | pthread_join(thread_id[i], NULL); 129 | 130 | printf("%llu\n", score - 1); 131 | } 132 | -------------------------------------------------------------------------------- /jelly/interpreter.py: -------------------------------------------------------------------------------- 1 | import cmath 2 | import copy 3 | import functools 4 | import hashlib 5 | import itertools 6 | import locale 7 | import math 8 | import operator 9 | import re 10 | import sys 11 | import time 12 | 13 | from .utils import attrdict, lazy_import 14 | 15 | random, sympy, urllib_request = lazy_import("random sympy urllib.request") 16 | 17 | code_page = '''¡¢£¤¥¦©¬®µ½¿€ÆÇÐÑרŒÞßæçðıȷñ÷øœþ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~¶''' # noqa: Q001 W605 18 | code_page += '''°¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾ƁƇƊƑƓƘⱮƝƤƬƲȤɓƈɗƒɠɦƙɱɲƥʠɼʂƭʋȥẠḄḌẸḤỊḲḶṂṆỌṚṢṬỤṾẈỴẒȦḂĊḊĖḞĠḢİĿṀṄȮṖṘṠṪẆẊẎŻạḅḍẹḥịḳḷṃṇọṛṣṭ§Äẉỵẓȧḃċḋėḟġḣŀṁṅȯṗṙṡṫẇẋẏż«»‘’“”''' # noqa: Q001 19 | code_page += "ṕṔÉ①ḳḾℙ≤≥Ď" # jellyfish specific 20 | 21 | # Unused symbols for single-byte atoms/quicks: (quƁƘȤėɦɱɲƥʠʂȥḥṇẉỵẓġṅẏ) 22 | 23 | str_digit = "0123456789" 24 | str_lower = "abcdefghijklmnopqrstuvwxyz" 25 | str_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 26 | 27 | inf = float("inf") 28 | nan = float("nan") 29 | sys.setrecursionlimit(1 << 30) 30 | 31 | def arities(links): 32 | return [link.arity for link in links] 33 | 34 | def at_index(index, array): 35 | array = iterable(array) 36 | if not array: 37 | return 0 38 | low_index = math.floor(index) - 1 39 | high_index = math.ceil(index) - 1 40 | if low_index == high_index: 41 | return array[low_index % len(array)] 42 | return [array[low_index % len(array)], array[high_index % len(array)]] 43 | 44 | def at_index_ndim(indices, array): 45 | retval = array 46 | for index in indices: 47 | retval = at_index(index, retval) 48 | return retval 49 | 50 | def base_decompression(integer, digits): 51 | digits = iterable(digits, make_range=True) 52 | return [digits[i-1] for i in to_base(integer, len(digits))] 53 | 54 | def bounce(array): 55 | return array[:-1] + array[::-1] 56 | 57 | def carmichael(n): 58 | n = int(n) 59 | if n < 1: 60 | return 0 61 | c = 1 62 | for p, k in sympy.ntheory.factor_.factorint(n).items(): 63 | c = lcm(c, 2 ** (k - 2) if p == 2 < k else (p - 1) * p ** (k - 1)) 64 | return c 65 | 66 | def create_chain(chain, arity = -1, is_forward = True): 67 | return attrdict( 68 | arity = arity, 69 | chain = chain, 70 | call = lambda x = None, y = None: variadic_chain(chain, is_forward and (x, y) or (y, x)) 71 | ) 72 | 73 | def create_literal(string): 74 | return attrdict( 75 | arity = 0, 76 | call = lambda: python_eval(string, False) 77 | ) 78 | 79 | def conv_dyadic_integer(link, larg, rarg): 80 | try: 81 | iconv_larg = int(larg) 82 | try: 83 | iconv_rarg = int(rarg) 84 | return link(iconv_larg, iconv_rarg) 85 | except Exception: 86 | return iconv_larg 87 | except Exception: 88 | try: 89 | return int(rarg) 90 | except Exception: 91 | return 0 92 | 93 | def conv_monadic_integer(link, arg): 94 | try: 95 | return link(int(arg)) 96 | except Exception: 97 | return 0 98 | 99 | def convolve(left, right): 100 | left, right = iterable(left, make_range = True), iterable(right, make_range = True) 101 | result = [0]*(len(left)+len(right)-1) 102 | for i,x in enumerate(left): 103 | for j,y in enumerate(right): 104 | result[i+j] += x*y 105 | return result 106 | 107 | def convolve_power(polynomial, exponent): 108 | retval = [1] 109 | for _ in range(exponent): 110 | retval = convolve(retval, polynomial) 111 | return retval 112 | 113 | def copy_to(atom, value): 114 | atom.call = lambda: value 115 | return value 116 | 117 | def determinant(matrix): 118 | matrix = sympy.Matrix(matrix) 119 | if matrix.is_square: 120 | return simplest_number(matrix.det()) 121 | return simplest_number(math.sqrt((matrix * matrix.transpose()).det())) 122 | 123 | def div(dividend, divisor, floor = False): 124 | if divisor == 0: 125 | return dividend * inf 126 | if divisor == inf: 127 | return 0 128 | if floor or (type(dividend) == int and type(divisor) == int and not dividend % divisor): 129 | return int(dividend // divisor) 130 | return dividend / divisor 131 | 132 | def depth(link): 133 | if type(link) != list: 134 | return 0 135 | if not link: 136 | return 1 137 | return 1 + max(map(depth, link)) 138 | 139 | def diagonals(matrix): 140 | shifted = [None] * len(matrix) 141 | for index, row in enumerate(map(iterable, reversed(matrix))): 142 | shifted[~index] = index * [None] + row 143 | return rotate_left(zip_ragged(shifted), len(matrix) - 1) 144 | 145 | def distinct_sieve(array): 146 | array = iterable(array, make_digits = True) 147 | result = [] 148 | for (i, x) in enumerate(array): 149 | result.append(1 if i == array.index(x) else 0) 150 | return result 151 | 152 | def dot_product(left, right, truncate = False): 153 | left, right = iterable(left), iterable(right) 154 | if complex in map(type, left + right): 155 | right = [complex(t).conjugate() for t in right] 156 | if truncate: 157 | product = sum(map(operator.mul, left, right)) 158 | else: 159 | product = sum(dyadic_link(atoms["×"], (left, right))) 160 | if product.imag == 0: 161 | product = product.real 162 | if type(product) != int and product.is_integer(): 163 | product = int(product) 164 | return product 165 | 166 | def dyadic_chain(chain, args): 167 | larg, rarg = args 168 | for link in chain: 169 | if link.arity < 0: 170 | link.arity = 2 171 | if chain and arities(chain[0:3]) == [2, 2, 2]: 172 | ret = dyadic_link(chain[0], args) 173 | chain = chain[1:] 174 | elif chain and arities(chain[0:3]) == [2, 1, 1]: 175 | ret = dyadic_link(chain[0], [monadic_link(chain[1], args[0]), monadic_link(chain[2], args[1])]) 176 | chain = chain[3:] 177 | elif leading_nilad(chain): 178 | ret = niladic_link(chain[0]) 179 | chain = chain[1:] 180 | else: 181 | ret = larg 182 | while chain: 183 | if arities(chain[0:3]) == [2, 2, 0] and leading_nilad(chain[2:]): 184 | ret = dyadic_link(chain[1], (dyadic_link(chain[0], (ret, rarg)), niladic_link(chain[2]))) 185 | chain = chain[3:] 186 | elif arities(chain[0:2]) == [2, 2]: 187 | ret = dyadic_link(chain[0], (ret, dyadic_link(chain[1], args))) 188 | chain = chain[2:] 189 | elif arities(chain[0:2]) == [2, 0]: 190 | ret = dyadic_link(chain[0], (ret, niladic_link(chain[1]))) 191 | chain = chain[2:] 192 | elif arities(chain[0:2]) == [0, 2]: 193 | ret = dyadic_link(chain[1], (niladic_link(chain[0]), ret)) 194 | chain = chain[2:] 195 | elif chain[0].arity == 2: 196 | ret = dyadic_link(chain[0], (ret, rarg)) 197 | chain = chain[1:] 198 | elif chain[0].arity == 1: 199 | ret = monadic_link(chain[0], ret) 200 | chain = chain[1:] 201 | else: 202 | output(ret) 203 | ret = niladic_link(chain[0]) 204 | chain = chain[1:] 205 | return ret 206 | 207 | def dyadic_link(link, args, conv = True, lflat = False, rflat = False): 208 | larg, rarg = args 209 | lflat = lflat or not hasattr(link, "ldepth") 210 | rflat = rflat or not hasattr(link, "rdepth") 211 | larg_depth = lflat or depth(larg) 212 | rarg_depth = rflat or depth(rarg) 213 | if (lflat or link.ldepth == larg_depth) and (rflat or link.rdepth == rarg_depth): 214 | if conv and hasattr(link, "conv"): 215 | return link.conv(link.call, larg, rarg) 216 | return link.call(larg, rarg) 217 | conv = conv and hasattr(link, "conv") 218 | if not lflat and larg_depth < link.ldepth: 219 | return dyadic_link(link, ([larg], rarg)) 220 | if not rflat and rarg_depth < link.rdepth: 221 | return dyadic_link(link, (larg, [rarg])) 222 | if not rflat and (lflat or larg_depth - rarg_depth < link.ldepth - link.rdepth): 223 | return [dyadic_link(link, (larg, y)) for y in rarg] 224 | if not lflat and (rflat or larg_depth - rarg_depth > link.ldepth - link.rdepth): 225 | return [dyadic_link(link, (x, rarg)) for x in larg] 226 | return [dyadic_link(link, (x, y)) for x, y in zip(*args)] + larg[len(rarg) :] + rarg[len(larg) :] 227 | 228 | def enumerate_md(array, upper_level = []): 229 | for i, item in enumerate(array): 230 | if type(item) != list: 231 | yield [upper_level + [i + 1], item] 232 | else: 233 | yield from enumerate_md(item, upper_level + [i + 1]) 234 | 235 | def equal(array): 236 | array = iterable(array) 237 | return int(all(item == array[0] for item in array)) 238 | 239 | def extremes(min_or_max, link, array): 240 | x,y = array 241 | x = iterable(x, make_range=True) 242 | if not x: 243 | return [] 244 | results = [variadic_link(link, (t, y)) for t in x] 245 | best = min_or_max(results) 246 | return [t for t, ft in zip(x, results) if ft == best][0] 247 | 248 | def filter_array(sand, mesh, is_in = True): 249 | mesh = {repr(element) for element in iterable(mesh)} 250 | return [element for element in iterable(sand) if (repr(element) in mesh) == is_in] 251 | 252 | def flatten(argument): 253 | flat = [] 254 | if type(argument) == list: 255 | for item in argument: 256 | flat += flatten(item) 257 | else: 258 | flat.append(argument) 259 | return flat 260 | 261 | def foldl(*args): 262 | return reduce(*args, arity = 2) 263 | 264 | def from_base(digits, base): 265 | integer = 0 266 | for digit in digits: 267 | integer = base * integer + digit 268 | return integer 269 | 270 | def from_diagonals(diagonals): 271 | upper_right = 1 272 | while len(diagonals[upper_right - 1]) > 1: 273 | upper_right += 1 274 | diagonals = rotate_left(diagonals, upper_right) 275 | shift = len(diagonals) - upper_right 276 | index = 0 277 | while shift: 278 | diagonals[index] = shift * [None] + diagonals[index] 279 | index += 1 280 | shift -= 1 281 | return zip_ragged(diagonals) 282 | 283 | def from_exponents(exponents): 284 | integer = 1 285 | for index, exponent in enumerate(exponents): 286 | integer *= sympy.ntheory.generate.prime(index + 1) ** exponent 287 | return integer 288 | 289 | def from_factorial_base(digits): 290 | place_value = 1 291 | integer = 0 292 | for next_place_index, digit in enumerate(digits[::-1], 1): 293 | integer += digit * place_value 294 | place_value *= next_place_index 295 | return integer 296 | 297 | def from_primorial_base(digits): 298 | integer = digits and digits[-1] or 0 299 | for place_index, digit in enumerate(digits[-2::-1], 1): 300 | integer += digit * sympy.ntheory.generate.primorial(place_index) 301 | return integer 302 | 303 | def simplest_number(number): 304 | if abs(number ** 2) != number ** 2: 305 | return number 306 | if number % 1: 307 | return float(number) 308 | return int(number) 309 | 310 | def get_request(url): 311 | url = "".join(map(str, url)) 312 | url = (re.match(r"[A-Za-z][A-Za-z0-9+.-]*://", url) is None and "http://" or "") + url 313 | response = urllib_request.request.urlopen(url).read() 314 | try: 315 | return list(response.decode("utf-8")) 316 | except Exception: 317 | return list(response.decode("latin-1")) 318 | 319 | def grid(array): 320 | if depth(array) == 1: 321 | return join(array, " ") 322 | if depth(array) == 2 and equal(map(len, array)): 323 | array = [[str(entry) for entry in row] for row in array] 324 | width = max(max([len(entry) for entry in row]) if row else 0 for row in array) 325 | array = [[list(entry.rjust(width)) for entry in row] for row in array] 326 | return join([join(row, " ") for row in array], "\n") 327 | if depth(array) == 3 and all(type(item) == str for item in flatten(array)): 328 | array = [["".join(entry) for entry in row] for row in array] 329 | width = max(max([len(entry) for entry in row]) if row else 0 for row in array) 330 | array = [[list(entry.ljust(width)) for entry in row] for row in array] 331 | return join([join(row, " ") for row in array], "\n") 332 | return join(array, "\n") 333 | 334 | def group(array): 335 | array = iterable(array, make_digits = True) 336 | grouped = {} 337 | for index, item in enumerate(array): 338 | item = repr(item) 339 | if item in grouped: 340 | grouped[item].append(index + 1) 341 | else: 342 | grouped[item] = [index + 1] 343 | try: 344 | return [grouped[key] for key in sorted(grouped, key = eval)] 345 | except TypeError: 346 | return [grouped[key] for key in sorted(grouped)] 347 | 348 | def group_md(array): 349 | array = iterable(array, make_digits = True) 350 | grouped = {} 351 | for index, item in enumerate_md(array): 352 | item = repr(item) 353 | if item in grouped: 354 | grouped[item].append(index) 355 | else: 356 | grouped[item] = [index] 357 | try: 358 | return [grouped[key] for key in sorted(grouped, key = eval)] 359 | except TypeError: 360 | return [grouped[key] for key in sorted(grouped)] 361 | 362 | def group_equal(array): 363 | array = iterable(array, make_digits = True) 364 | groups = [] 365 | for x in array: 366 | if groups and groups[-1][0] == x: 367 | groups[-1].append(x) 368 | else: 369 | groups.append([x]) 370 | return groups 371 | 372 | def partition(array): 373 | array = iterable(array, make_digits = True) 374 | return list(filter(lambda x: x[0] > 0, group_equal(array))) 375 | 376 | def partition_with(links, outmost_links, index): 377 | ret = [attrdict(arity = 1)] 378 | ret[0].call = lambda z: [monadic_link(links[0], t) for t in partition(z)] 379 | return ret 380 | 381 | def partition_by(links, outmost_links, index): 382 | ret = [attrdict(arity = 1)] 383 | ret[0].call = lambda z: [list(t[1]) for t in itertools.groupby(z, lambda x: monadic_link(links[0], x)) if t[0]] 384 | return ret 385 | 386 | def partition_lengths(array): 387 | array = iterable(array, make_digits = True) 388 | return list(len(t) for t in partition(array)) 389 | 390 | def keep(mask, array): 391 | return [val for val, m in zip(array, mask) if m] 392 | 393 | def identity(argument): 394 | return argument 395 | 396 | def iterable(argument, make_copy = False, make_digits = False, make_range = False): 397 | the_type = type(argument) 398 | if the_type == list: 399 | return copy.deepcopy(argument) if make_copy else argument 400 | if the_type != str and make_digits: 401 | return to_base(argument, 10) 402 | if the_type != str and make_range: 403 | return list(range(1, int(argument) + 1)) 404 | return [argument] 405 | 406 | def index_of(haystack, needle): 407 | for index, item in enumerate(iterable(haystack)): 408 | if item == needle: 409 | return 1 + index 410 | return 0 411 | 412 | def index_of_md(haystack, needle): 413 | for index, item in enumerate_md(haystack): 414 | if item == needle: 415 | return index 416 | return [] 417 | 418 | def indices_md(array, upper_level = []): 419 | a_indices = [] 420 | for i, item in enumerate(array): 421 | if type(item) != list: 422 | a_indices.append(upper_level + [i + 1]) 423 | else: 424 | a_indices.extend(indices_md(item, upper_level = upper_level + [i + 1])) 425 | return a_indices 426 | 427 | def isqrt(number): 428 | a = number 429 | b = (a + 1) // 2 430 | while b < a: 431 | a = b 432 | b = (a + number // a) // 2 433 | return int(a) 434 | 435 | def is_palindrome(argument): 436 | argument = iterable(argument, make_digits = True) 437 | return int(argument == argument[::-1]) 438 | 439 | def is_string(argument): 440 | if type(argument) != list: 441 | return False 442 | return all(map(lambda t: type(t) == str, argument)) 443 | 444 | def jelly_eval(code, arguments): 445 | return variadic_chain(parse_code(code)[-1] if code else "", arguments) 446 | 447 | def jelly_hash(spec, object): 448 | if len(spec) > 2: 449 | spec = [spec[0], spec[1:]] 450 | if type(spec[0]) == list: 451 | digits = [code_page.find(item) if type(item) == str else item for item in spec[0]] 452 | magic = from_base([digit + 1 for digit in digits], 250) + 1 453 | else: 454 | magic = spec[0] + 1 455 | 456 | buckets = spec[1] if type(spec[1]) == list else range(1, spec[1] + 1) 457 | 458 | shake = hashlib.shake_256(repr(object).encode("utf-8")).digest(512) 459 | longs = [int.from_bytes(shake[i : i + 8], "little") for i in range(0, 512, 8)] 460 | temp = sum(((magic >> i) - (magic >> i + 1)) * longs[i] for i in range(64)) 461 | hash = temp % 2**64 * len(buckets) >> 64 462 | return buckets[hash - 1] 463 | 464 | def jelly_uneval(argument, top = True): 465 | the_type = type(argument) 466 | if the_type in (float, int): 467 | return jelly_uneval_real(argument) 468 | if the_type == complex: 469 | return jelly_uneval_real(argument.real) + "ı" + jelly_uneval_real(argument.imag) 470 | if the_type == str: 471 | return "”" + argument 472 | if all(map(is_string, argument)): 473 | strings = ["".join(string) for string in argument] 474 | if all(map(lambda t: code_page.find(t) < 250, "".join(strings))): 475 | return "“" + "“".join(strings) + "”" 476 | if is_string(argument): 477 | string = "".join(argument) 478 | if all(map(lambda t: code_page.find(t) < 250, string)): 479 | return "“" + string + "”" 480 | middle = ",".join(jelly_uneval(item, top = False) for item in argument) 481 | return middle if top else "[" + middle + "]" 482 | 483 | def jelly_uneval_real(number): 484 | string = str(number if number % 1 else int(number)) 485 | return string.lstrip("0") if number else string 486 | 487 | def jellify(element, dirty = False): 488 | if element is None: 489 | return [] 490 | if type(element) == str and dirty: 491 | return list(element) 492 | if type(element) in (int, float, complex) or (type(element) == str and len(element) == 1): 493 | return element 494 | try: 495 | return [jellify(item, dirty) for item in element] 496 | except Exception: 497 | if element.is_integer: 498 | return int(element) 499 | if element.is_real: 500 | return float(element) 501 | return complex(element) 502 | 503 | def join(array, glue): 504 | array = iterable(array, make_copy = True) 505 | last = array.pop() if array else [] 506 | glue = iterable(glue) 507 | ret = [] 508 | for item in array: 509 | ret += iterable(item) + glue 510 | return ret + iterable(last) 511 | 512 | def last_input(): 513 | if len(sys.argv) > 3: 514 | return python_eval(sys.argv[-1]) 515 | return python_eval(input()) 516 | 517 | def leading_nilad(chain): 518 | return chain and arities(chain) + [1] < [0, 2] * len(chain) 519 | 520 | def lcm(x, y): 521 | return x * y // (math.gcd(x, y) or 1) 522 | 523 | def loop_until_loop(link, args, return_all = False, return_loop = False, vary_rarg = True): 524 | ret, rarg = args 525 | cumret = [] 526 | while True: 527 | cumret.append(ret) 528 | larg = ret 529 | ret = variadic_link(link, (larg, rarg)) 530 | if vary_rarg: 531 | rarg = larg 532 | if ret in cumret: 533 | if return_all: 534 | return cumret 535 | if return_loop: 536 | return cumret[index_of(cumret, ret) - 1 :] 537 | return larg 538 | 539 | def nfind(links, args): 540 | larg, rarg = args 541 | larg = larg or 0 542 | matches = variadic_link(links[1], args) if len(links) == 2 else last_input() 543 | found = [] 544 | while len(found) < matches: 545 | if variadic_link(links[0], (larg, rarg)): 546 | found.append(larg) 547 | larg += 1 548 | return found 549 | 550 | def matrix_to_list(matrix): 551 | return [[simplest_number(entry) for entry in row] for row in matrix.tolist()] 552 | 553 | def max_arity(links): 554 | return max(arities(links)) if min(arities(links)) > -1 else (~max(arities(links)) or -1) 555 | 556 | def maximal_indices(iterable): 557 | maximum = max(iterable or [0]) 558 | return [u + 1 for u, v in enumerate(iterable) if v == maximum] 559 | 560 | def maximal_indices_md(iterable, upper_level = [], maximum = None): 561 | if maximum is None: 562 | maximum = max(flatten(iterable) or [0]) 563 | result = [] 564 | for i, item in enumerate(iterable): 565 | if type(item) != list: 566 | if item == maximum: 567 | result.append(upper_level + [i + 1]) 568 | else: 569 | result.extend(maximal_indices_md(item, upper_level = upper_level + [i + 1], maximum = maximum)) 570 | return result 571 | 572 | def median(array): 573 | array = sorted(array) 574 | return div(array[(len(array) - 1) // 2] + array[len(array) // 2], 2) 575 | 576 | def mode(array): 577 | frequencies = {} 578 | maxfreq = 0 579 | retval = [] 580 | for element in array: 581 | string = repr(element) 582 | frequencies[string] = frequencies.get(string, 0) + 1 583 | maxfreq = max(frequencies[string], maxfreq) 584 | for element in array: 585 | string = repr(element) 586 | if frequencies[string] == maxfreq: 587 | retval.append(element) 588 | frequencies[string] = 0 589 | return retval 590 | 591 | def modinv(a, m): 592 | i, _, g = sympy.numbers.igcdex(a, m) 593 | return i % m if g == 1 else 0 594 | 595 | def modulus(dividend, divisor): 596 | try: 597 | return dividend % divisor 598 | except Exception: 599 | return nan 600 | 601 | def mold(content, shape): 602 | for index in range(len(shape)): 603 | if type(shape[index]) == list: 604 | mold(content, shape[index]) 605 | else: 606 | item = content.pop(0) 607 | shape[index] = item 608 | content.append(item) 609 | return shape 610 | 611 | def monadic_chain(chain, arg): 612 | init = True 613 | ret = arg 614 | larg_save = atoms["⁸"].call 615 | while True: 616 | if init: 617 | for link in chain: 618 | if link.arity < 0: 619 | link.arity = 1 620 | if leading_nilad(chain): 621 | ret = niladic_link(chain[0]) 622 | chain = chain[1:] 623 | init = False 624 | if not chain: 625 | break 626 | if arities(chain[0:2]) == [2, 1]: 627 | ret = dyadic_link(chain[0], (ret, monadic_link(chain[1], arg))) 628 | chain = chain[2:] 629 | elif arities(chain[0:2]) == [2, 0]: 630 | ret = dyadic_link(chain[0], (ret, niladic_link(chain[1]))) 631 | chain = chain[2:] 632 | elif arities(chain[0:2]) == [0, 2]: 633 | ret = dyadic_link(chain[1], (niladic_link(chain[0]), ret)) 634 | chain = chain[2:] 635 | elif chain[0].arity == 2: 636 | ret = dyadic_link(chain[0], (ret, arg)) 637 | chain = chain[1:] 638 | elif chain[0].arity == 1: 639 | if not chain[1:] and hasattr(chain[0], "chain"): 640 | arg = ret 641 | chain = chain[0].chain 642 | atoms["⁸"].call = lambda literal = arg: literal 643 | init = True 644 | else: 645 | ret = monadic_link(chain[0], ret) 646 | chain = chain[1:] 647 | else: 648 | output(ret) 649 | ret = niladic_link(chain[0]) 650 | chain = chain[1:] 651 | atoms["⁸"].call = larg_save 652 | return ret 653 | 654 | def monadic_link(link, arg, flat = False, conv = True): 655 | flat = flat or not hasattr(link, "ldepth") 656 | arg_depth = flat or depth(arg) 657 | if flat or link.ldepth == arg_depth: 658 | if conv and hasattr(link, "conv"): 659 | return link.conv(link.call, arg) 660 | return link.call(arg) 661 | conv = conv and hasattr(link, "conv") 662 | if link.ldepth > arg_depth: 663 | return monadic_link(link, [arg], conv = conv) 664 | return [monadic_link(link, z, conv = conv) for z in arg] 665 | 666 | def multiset_difference(left, right): 667 | result = iterable(left)[::-1] 668 | for element in iterable(right): 669 | if element in result: 670 | result.remove(element) 671 | return result[::-1] 672 | 673 | def multiset_intersect(left, right): 674 | right = iterable(right, make_copy = True) 675 | result = [] 676 | for element in iterable(left): 677 | if element in right: 678 | result.append(element) 679 | right.remove(element) 680 | return result 681 | 682 | def multiset_symdif(left, right): 683 | return multiset_union(multiset_difference(left, right), multiset_difference(right, left)) 684 | 685 | def multiset_union(left, right): 686 | return iterable(left) + multiset_difference(right, left) 687 | 688 | def nCr(left, right): # noqa N802 689 | if type(left) == int and type(right) == int: 690 | if right < 0: 691 | right = left - right 692 | if right < 0 or (left > 0 and right > left): 693 | return 0 694 | if left > 0: 695 | right = min(right, left - right) 696 | result = 1 697 | for i in range(right): 698 | result = result * (left - i) // (i + 1) 699 | return result 700 | return div(Pi(left), Pi(left - right) * Pi(right)) 701 | 702 | def niladic_chain(chain): 703 | while len(chain) == 1 and hasattr(chain[0], "chain"): 704 | chain = chain[0].chain 705 | if not chain or chain[0].arity > 0: 706 | return monadic_chain(chain, 0) 707 | return monadic_chain(chain[1:], chain[0].call()) 708 | 709 | def niladic_link(link): 710 | return link.call() 711 | 712 | def ntimes(links, args, cumulative = False): 713 | ret, rarg = args 714 | repetitions = variadic_link(links[1], args) if len(links) == 2 else last_input() 715 | repetitions = overload((int, bool), repetitions) 716 | if cumulative: 717 | cumret = [0] * repetitions 718 | for index in range(repetitions): 719 | if cumulative: 720 | cumret[index] = ret 721 | larg = ret 722 | ret = variadic_link(links[0], (larg, rarg)) 723 | rarg = larg 724 | return cumret + [ret] if cumulative else ret 725 | 726 | def odd_even(array): 727 | array = iterable(array, make_range = True) 728 | return [[t for t in array[::2]], [t for t in array[1::2]]] 729 | 730 | def order(number, divisor): 731 | if number == 0 or abs(divisor) == 1: 732 | return inf 733 | if divisor == 0: 734 | return 0 735 | ret = 0 736 | while True: 737 | number, residue = divmod(number, divisor) 738 | if residue: 739 | break 740 | ret += 1 741 | return ret 742 | 743 | def overload(operators, *args): 744 | for op in operators: 745 | try: 746 | ret = op(*args) 747 | except Exception: 748 | pass 749 | else: 750 | return ret 751 | return None 752 | 753 | def integer_partitions(n, I=1): 754 | result = [[n,]] 755 | for i in range(I, n//2 + 1): 756 | for p in integer_partitions(n-i, i): 757 | result.append([i,] + p) 758 | return result 759 | 760 | def neighbors(links, array): 761 | array = iterable(array, make_digits = True) 762 | chain = dyadic_chain if links[-1].arity == 2 else monadic_chain 763 | return [chain(links, list(pair)) for pair in zip(array, array[1:])] 764 | 765 | def partitions(array): 766 | array = iterable(array, make_digits = True) 767 | ret = [] 768 | for index in range(1, len(array)): 769 | for subarray in partitions(array[index:]): 770 | subarray.insert(0, array[:index]) 771 | ret.append(subarray) 772 | ret.append([array]) 773 | return ret 774 | 775 | def parse_code(code): 776 | lines = regex_flink.findall(code) 777 | links = [[] for line in lines] 778 | for index, line in enumerate(lines): 779 | chains = links[index] 780 | for word in regex_chain.findall(line): 781 | chain = [] 782 | arity, start, is_forward = chain_separators.get(word[:1], default_chain_separation) 783 | for token in regex_token.findall(start + word): 784 | if token in atoms: 785 | chain.append(atoms[token]) 786 | elif token in quicks: 787 | popped = [] 788 | while not quicks[token].condition(popped) and (chain or chains): 789 | popped.insert(0, chain.pop() if chain else chains.pop()) 790 | chain += quicks[token].quicklink(popped, links, index) 791 | elif token in hypers: 792 | x = chain.pop() if chain else chains.pop() 793 | chain.append(hypers[token](x, links)) 794 | else: 795 | chain.append(create_literal(regex_liter.sub(parse_literal, token))) 796 | chains.append(create_chain(chain, arity, is_forward)) 797 | return links 798 | 799 | def parse_literal(literal_match): 800 | literal = literal_match.group(0) 801 | if literal[0] in "”⁾": 802 | return repr(literal[1:].replace("¶", "\n")) 803 | if literal[0] == "“": 804 | if literal[-1] in "«»‘’”": 805 | mode = literal[-1] 806 | literal = literal[:-1] 807 | else: 808 | mode = "" 809 | parsed = literal.split("“")[1:] 810 | if mode == "»": 811 | parsed = [sss(string).replace("¶", "\n") for string in parsed] 812 | elif mode == "‘": 813 | parsed = [[code_page.find(char) for char in string] for string in parsed] 814 | elif mode == "’": 815 | parsed = [from_base([code_page.find(char) + 1 for char in string], 250) for string in parsed] 816 | else: 817 | parsed = [string.replace("¶", "\n") for string in parsed] 818 | if mode not in "‘’": 819 | parsed = [[string] if len(string) == 1 else string for string in parsed] 820 | if len(parsed) == 1: 821 | parsed = parsed[0] 822 | elif literal[0] == "⁽": 823 | parsed = from_base([code_page.find(char) + 1 for char in literal[1:]], 250) 824 | parsed += parsed > 31500 and -62850 or 750 825 | else: 826 | parsed = eval("+ 1j *".join([ 827 | repr(eval("* 10 **".join(["-1" if part == "-" else (part + "5" if part[-1:] == "." else part) or repr(2 * index + 1) 828 | for index, part in enumerate(component.split("ȷ"))])) if component else index) 829 | for index, component in enumerate(literal.split("ı")) 830 | ])) 831 | return repr(parsed) + " " 832 | 833 | def partition_at(booleans, array, border = 1): 834 | booleans = iterable(booleans) 835 | array = iterable(array) 836 | chunks = [[], []] 837 | index = 0 838 | while index < len(array): 839 | if index < len(booleans) and booleans[index]: 840 | chunks.append([]) 841 | chunks[-border].append(array[index]) 842 | else: 843 | chunks[-1].append(array[index]) 844 | index += 1 845 | return chunks[1:] 846 | 847 | def pemutation_at_index(index, array = None): 848 | result = [] 849 | if array is None: 850 | divisor = 1 851 | count = 0 852 | while divisor < index: 853 | count += 1 854 | divisor *= count 855 | values = list(range(1, count + 1)) 856 | else: 857 | values = iterable(array, make_copy = True, make_range = True) 858 | try: 859 | divisor = math.factorial(len(values)) 860 | except Exception: 861 | divisor = functools.reduce(operator.mul, range(1, len(values) + 1), 1) 862 | index -= 1 863 | index %= divisor 864 | while values: 865 | divisor //= len(values) 866 | quotient, index = divmod(index, divisor) 867 | result.append(values.pop(quotient)) 868 | return result 869 | 870 | def permutation_index(array): 871 | result = 1 872 | array = iterable(array) 873 | length = len(array) 874 | for index in range(length): 875 | k = sum(1 for value in array[index + 1:] if value < array[index]) 876 | try: 877 | factor = math.factorial(length - index - 1) 878 | except Exception: 879 | factor = functools.reduce(operator.mul, range(1, length - index), 1) 880 | result += k * factor 881 | return result 882 | 883 | def Pi(number): 884 | if type(number) == int: 885 | if number < 0: 886 | return inf 887 | try: 888 | return math.factorial(number) 889 | except Exception: 890 | return functools.reduce(operator.mul, range(1, number + 1), 1) 891 | return math.gamma(number + 1) 892 | 893 | def powerset(array): 894 | array = iterable(array, make_range = True) 895 | ret = [] 896 | for t in range(len(array) + 1): 897 | ret += jellify(itertools.combinations(array, t)) 898 | return ret 899 | 900 | def prefix(links, outmost_links, index): 901 | ret = [attrdict(arity = max(1, links[0].arity))] 902 | if len(links) == 1: 903 | ret[0].call = lambda x, y = None: [variadic_link(links[0], (t, y)) for t in split_prefix(x)] 904 | else: 905 | ret[0].call = lambda x, y = None: [variadic_link(links[0], (t, y)) for t in split_rolling(x, niladic_link(links[1]))] 906 | return ret 907 | 908 | def primerange(start, end): 909 | if start > end: 910 | return list(sympy.primerange(end, start + 1))[::-1] 911 | return list(sympy.primerange(start, end + 1)) 912 | 913 | def python_eval(string, dirty = True): 914 | try: 915 | return jellify(eval(string), dirty) 916 | except SyntaxError: 917 | exec(string) 918 | return [] 919 | 920 | def quickchain(arity, min_length): 921 | return attrdict( 922 | condition = 923 | (lambda links: len(links) >= min_length and links[0].arity == 0) 924 | if arity == 0 else 925 | lambda links: 926 | len(links) - sum(map(leading_nilad, split_suffix(links)[:-1])) >= min_length, 927 | quicklink = lambda links, outmost_links, index: [attrdict( 928 | arity = arity, 929 | call = lambda x = None, y = None: variadic_chain(links, (x, y)) 930 | )] 931 | ) 932 | 933 | def random_int(pool): 934 | if not pool: 935 | return 0 936 | if type(pool) == list: 937 | return random.choice(pool) 938 | return random.randint(1, pool) 939 | 940 | def reduce(links, outmost_links, index, arity = 1): 941 | ret = [attrdict(arity = arity)] 942 | if len(links) == 1: 943 | ret[0].call = lambda x, *y: reduce_simple(x, links[0], *y) 944 | else: 945 | ret[0].call = lambda x, *y: [reduce_simple(t, links[0], *y) for t in split_fixed(iterable(x), links[1].call())] 946 | return ret 947 | 948 | def reduce_simple(array, link, *init): 949 | array = iterable(array) 950 | return functools.reduce(lambda x, y: dyadic_link(link, (x, y)), array, *init) 951 | 952 | def prior(links, outmost_links, index): 953 | ret = [attrdict(arity = 1)] 954 | ret[0].call = lambda z: [reduce_simple(t, links[0]) for t in split_rolling(iterable(z), 2)] 955 | return ret 956 | 957 | def group_op(links, outmost_links, index): 958 | ret = [attrdict(arity = 1)] 959 | ret[0].call = lambda z: [monadic_link(links[0], t) for t in group_equal(z)] 960 | return ret 961 | 962 | def reduce_cumulative(links, outmost_links, index): 963 | ret = [attrdict(arity = 1)] 964 | if len(links) == 1: 965 | ret[0].call = lambda t: list(itertools.accumulate(iterable(t), lambda x, y: dyadic_link(links[0], (x, y)))) 966 | else: 967 | ret[0].call = lambda z: [reduce_simple(t, links[0]) for t in split_rolling(iterable(z), links[1].call())] 968 | return ret 969 | 970 | def rld(runs): 971 | return list(itertools.chain(*[[u] * v for u, v in runs])) 972 | 973 | def rle(array): 974 | return [[group[0], len(group)] for group in group_equal(array)] 975 | 976 | def rotate_left(array, units): 977 | array = iterable(array) 978 | length = len(array) 979 | return array[units % length :] + array[: units % length] if length else [] 980 | 981 | def shift_left(number, bits): 982 | if type(number) == int and type(bits) == int: 983 | return number << bits 984 | return number * 2 ** bits 985 | 986 | def shift_right(number, bits): 987 | if type(number) == int and type(bits) == int: 988 | return number >> bits 989 | return div(number, 2 ** bits, floor = True) 990 | 991 | def shuffle(array): 992 | array = iterable(array, make_copy = True, make_range = True) 993 | random.shuffle(array) 994 | return array 995 | 996 | def sparse(link, args, indices, indices_literal = False): 997 | larg = args[0] 998 | if not indices_literal: 999 | indices = iterable(variadic_link(indices, args)) 1000 | indices = [index - 1 if index > 0 else index - 1 + len(larg) for index in indices] 1001 | ret = iterable(variadic_link(link, args)) 1002 | return [ret[t % len(ret)] if t in indices else u for t, u in enumerate(larg)] 1003 | 1004 | def split_around(array, needle): 1005 | chunk = [] 1006 | window = len(needle) 1007 | index = 0 1008 | while index < len(array): 1009 | if array[index : index + window] == needle: 1010 | yield chunk 1011 | chunk = [] 1012 | index += window 1013 | else: 1014 | chunk.append(array[index]) 1015 | index += 1 1016 | yield chunk 1017 | 1018 | def split_at(array, needle): 1019 | chunk = [] 1020 | for element in array: 1021 | if element == needle: 1022 | yield chunk 1023 | chunk = [] 1024 | else: 1025 | chunk.append(element) 1026 | yield chunk 1027 | 1028 | def split_evenly(array, chunks): 1029 | array = iterable(array) 1030 | min_width, overflow = divmod(len(array), chunks) 1031 | ret = [] 1032 | high = 0 1033 | for index in range(chunks): 1034 | low = high 1035 | high = low + min_width + (index < overflow) 1036 | ret.append(array[low : high]) 1037 | return ret 1038 | 1039 | def split_fixed(array, width): 1040 | if width < 0: 1041 | return split_fixed_out(array, -width) 1042 | array = iterable(array) 1043 | return [array[index : index + width] for index in range(0, len(array), width)] 1044 | 1045 | def split_fixed_out(array, width): 1046 | array = iterable(array) 1047 | return [array[:index] + array[index + width:] for index in range(0, len(array), width)] 1048 | 1049 | def split_key(control, data): 1050 | groups = {} 1051 | order = [] 1052 | count = 0 1053 | for key, item in zip(control, data): 1054 | key = repr(key) if type(key) == list else key 1055 | if key not in groups: 1056 | order.append(key) 1057 | groups[key] = [] 1058 | groups[key].append(item) 1059 | count += 1 1060 | result = [groups[key] for key in order] 1061 | if count < len(data): 1062 | result.append(data[count:]) 1063 | return result 1064 | 1065 | def split_once(array, needle): 1066 | array = iterable(array, make_digits = True) 1067 | index = index_of(array, needle) 1068 | return [array[0 : index - 1], array[index :]] if index else [array] 1069 | 1070 | def split_prefix(array): 1071 | array = iterable(array) 1072 | return [array[:index + 1] for index in range(len(array))] 1073 | 1074 | def split_rolling(array, width): 1075 | if width < 0: 1076 | return split_rolling_out(array, -width) 1077 | array = iterable(array) 1078 | return [array[index : index + width] for index in range(len(array) - width + 1)] 1079 | 1080 | def split_rolling_out(array, width): 1081 | array = iterable(array) 1082 | return [array[:index] + array[index + width:] for index in range(len(array) - width + 1)] 1083 | 1084 | def split_suffix(array): 1085 | array = iterable(array) 1086 | return [array[index:] for index in range(len(array))] 1087 | 1088 | def sss(compressed): 1089 | from . import dictionary 1090 | decompressed = "" 1091 | integer = from_base([code_page.find(char) + 1 for char in compressed], 250) 1092 | while integer: 1093 | integer, mode = divmod(integer, 3) 1094 | if mode == 0: 1095 | integer, code = divmod(integer, 96) 1096 | decompressed += code_page[code + 32] 1097 | else: 1098 | flag_swap = False 1099 | flag_space = decompressed != "" 1100 | if mode == 2: 1101 | integer, flag = divmod(integer, 3) 1102 | flag_swap = flag != 1 1103 | flag_space ^= flag != 0 1104 | integer, short = divmod(integer, 2) 1105 | the_dictionary = (dictionary.long, dictionary.short)[short] 1106 | integer, index = divmod(integer, len(the_dictionary)) 1107 | word = the_dictionary[index] 1108 | if flag_swap: 1109 | word = word[0].swapcase() + word[1:] 1110 | if flag_space: 1111 | word = " " + word 1112 | decompressed += word 1113 | return decompressed 1114 | 1115 | def stringify(iterable, recurse = True): 1116 | if type(iterable) != list: 1117 | return iterable 1118 | if len(iterable) == 1: 1119 | return stringify(iterable[0]) 1120 | if str in map(type, iterable) and list not in map(type, iterable) or not iterable: 1121 | return "".join(map(str, iterable)) 1122 | iterable = [stringify(item) for item in iterable] 1123 | return stringify(iterable, False) if recurse else iterable 1124 | 1125 | def suffix(links, outmost_links, index): 1126 | ret = [attrdict(arity = max(1, links[0].arity))] 1127 | if len(links) == 1: 1128 | ret[0].call = lambda x, y = None: [variadic_link(links[0], (t, y)) for t in split_suffix(x)] 1129 | else: 1130 | ret[0].call = lambda x, y = None: [variadic_link(links[0], (t, y)) for t in split_fixed(x, niladic_link(links[1]))] 1131 | return ret 1132 | 1133 | def symmetric_mod(number, half_divisor): 1134 | modulus = number % (2 * half_divisor) 1135 | return modulus - 2 * half_divisor * (modulus > half_divisor) 1136 | 1137 | def tie(links, outmost_links, index): 1138 | ret = [attrdict(arity= max(1, *arities(links)))] 1139 | n = 2 if links[-1].arity else links[-1].call() 1140 | def _make_tie(): 1141 | i = 0 1142 | while True: 1143 | yield links[i] 1144 | i = (i + 1) % n 1145 | cycle = _make_tie() 1146 | ret[0].call = lambda x = None, y = None: variadic_link(next(cycle), (x, y)) 1147 | return ret 1148 | 1149 | def time_format(bitfield): 1150 | time_string = ":".join(["%H"] * (bitfield & 4 > 0) + ["%M"] * (bitfield & 2 > 0) + ["%S"] * (bitfield & 1 > 0)) 1151 | return list(time.strftime(time_string)) 1152 | 1153 | def translate(mapping, array): 1154 | array = iterable(array, make_copy = True) 1155 | mapping = iterable(mapping, make_copy = True) 1156 | while mapping: 1157 | source = iterable(mapping.pop(0)) 1158 | destination = iterable(mapping.pop(0)) 1159 | for (index, item) in enumerate(array): 1160 | if item in source: 1161 | array[index] = destination[min(source.index(item), len(destination) - 1)] 1162 | return array 1163 | 1164 | def trim(trimmee, trimmer, left = False, right = False): 1165 | lindex = 0 1166 | rindex = len(trimmee) 1167 | if left: 1168 | while lindex < rindex and trimmee[lindex] in trimmer: 1169 | lindex += 1 1170 | if right: 1171 | while lindex < rindex and trimmee[rindex - 1] in trimmer: 1172 | rindex -= 1 1173 | return trimmee[lindex:rindex] 1174 | 1175 | def try_eval(string): 1176 | try: 1177 | return python_eval(string) 1178 | except Exception: 1179 | return jellify(string, True) 1180 | 1181 | def to_base(integer, base, bijective = False): 1182 | if integer == 0: 1183 | return [0] * (not bijective) 1184 | if bijective: 1185 | base = abs(base) 1186 | if base == 0: 1187 | return [integer] 1188 | if base == -1: 1189 | digits = [1, 0] * abs(integer) 1190 | return digits[:-1] if integer > 0 else digits 1191 | sign = -1 if integer < 0 and base > 0 else 1 1192 | integer *= sign 1193 | if base == 1: 1194 | return [sign] * integer 1195 | digits = [] 1196 | while integer: 1197 | integer -= bijective 1198 | integer, digit = divmod(integer, base) 1199 | digit += bijective 1200 | if digit < 0: 1201 | integer += 1 1202 | digit -= base 1203 | digits.append(sign * digit) 1204 | return digits[::-1] 1205 | 1206 | def to_case(argument, lower = False, swap = False, title = False, upper = False): 1207 | ret = [] 1208 | last_item = " " 1209 | for item in argument: 1210 | if type(item) == str: 1211 | if lower: 1212 | ret.append(item.lower()) 1213 | elif swap: 1214 | ret.append(item.swapcase()) 1215 | elif title: 1216 | ret.append(item.lower() if type(last_item) == str and last_item in str_upper + str_lower else item.upper()) 1217 | elif upper: 1218 | ret.append(item.upper()) 1219 | else: 1220 | ret.append(item) 1221 | last_item = item 1222 | return ret 1223 | 1224 | def to_exponents(integer): 1225 | if integer == 1: 1226 | return [] 1227 | pairs = sympy.ntheory.factor_.factorint(integer) 1228 | exponents = [] 1229 | for prime in sympy.ntheory.generate.primerange(2, max(pairs) + 1): 1230 | if prime in pairs: 1231 | exponents.append(pairs[prime]) 1232 | else: 1233 | exponents.append(0) 1234 | return exponents 1235 | 1236 | def to_factorial_base(integer): 1237 | radix = 1 1238 | digits = [] 1239 | while integer: 1240 | integer, remainder = divmod(integer, radix) 1241 | digits.append(remainder) 1242 | radix += 1 1243 | return digits[::-1] or [0] 1244 | 1245 | def to_primorial_base(integer): 1246 | place_index = 1 1247 | integer, remainder = divmod(integer, 2) 1248 | digits = [remainder] 1249 | while integer: 1250 | place_index += 1 1251 | integer, remainder = divmod(integer, sympy.ntheory.generate.prime(place_index)) 1252 | digits.append(remainder) 1253 | return digits[::-1] 1254 | 1255 | def unicode_to_jelly(string): 1256 | return "".join(chr(code_page.find(char)) for char in str(string).replace("\n", "¶") if char in code_page) 1257 | 1258 | def unique(array): 1259 | array = iterable(array, make_digits = True) 1260 | result = [] 1261 | for element in array: 1262 | if element not in result: 1263 | result.append(element) 1264 | return result 1265 | 1266 | def untruth_md(indices, shape = None, upper_level = []): 1267 | if not shape: 1268 | shape = [max(index_zipped) for index_zipped in zip(*indices)] 1269 | upper_len = len(upper_level) 1270 | if upper_len < len(shape) - 1: 1271 | return [untruth_md(indices, shape = shape, upper_level = upper_level + [i + 1]) for i in range(shape[upper_len])] 1272 | return [1 if (upper_level + [i + 1] in indices) else 0 for i in range(shape[-1])] 1273 | 1274 | def variadic_chain(chain, args): 1275 | args = list(filter(None.__ne__, args)) 1276 | larg_save = atoms["⁸"].call 1277 | rarg_save = atoms["⁹"].call 1278 | if len(args) == 0: 1279 | return niladic_chain(chain) 1280 | if len(args) == 1: 1281 | atoms["⁸"].call = lambda literal = args[0]: literal 1282 | ret = monadic_chain(chain, args[0]) 1283 | if len(args) == 2: 1284 | atoms["⁸"].call = lambda literal = args[0]: literal 1285 | atoms["⁹"].call = lambda literal = args[1]: literal 1286 | ret = dyadic_chain(chain, args) 1287 | atoms["⁸"].call = larg_save 1288 | atoms["⁹"].call = rarg_save 1289 | return ret 1290 | 1291 | def variadic_link(link, args, flat = False, lflat = False, rflat = False): 1292 | if link.arity < 0: 1293 | args = list(filter(None.__ne__, args)) 1294 | link.arity = len(args) 1295 | if link.arity == 0: 1296 | return niladic_link(link) 1297 | if link.arity == 1: 1298 | return monadic_link(link, args[0], flat) 1299 | if link.arity == 2: 1300 | return dyadic_link(link, args, lflat, rflat) 1301 | return None 1302 | 1303 | def while_loop(link, condition, args, cumulative = False): 1304 | ret, rarg = args 1305 | cumret = [] 1306 | while variadic_link(condition, (ret, rarg)): 1307 | if cumulative: 1308 | cumret.append(ret) 1309 | larg = ret 1310 | ret = variadic_link(link, (larg, rarg)) 1311 | rarg = larg 1312 | return cumret + [ret] if cumulative else ret 1313 | 1314 | def windowed_exists(needle, haystack): 1315 | haystack = iterable(haystack, make_digits = True) 1316 | needle = iterable(needle, make_digits = True) 1317 | needle_length = len(needle) 1318 | for index in range(len(haystack)): 1319 | if haystack[index : index + needle_length] == needle: 1320 | return 1 1321 | return 0 1322 | 1323 | def windowed_index_of(haystack, needle): 1324 | haystack = iterable(haystack, make_digits = True) 1325 | needle = iterable(needle, make_digits = True) 1326 | needle_length = len(needle) 1327 | for index in range(len(haystack)): 1328 | if haystack[index : index + needle_length] == needle: 1329 | return 1 + index 1330 | return 0 1331 | 1332 | def windowed_sublists(array): 1333 | array = iterable(array, make_range = True) 1334 | return [sublist for width in range(1, len(array) + 1) for sublist in split_rolling(array, width)] 1335 | 1336 | def output(argument, end = "", transform = stringify): 1337 | if locale.getdefaultlocale()[1][0:3] == "UTF": 1338 | print(transform(argument), end = end) 1339 | else: 1340 | print(unicode_to_jelly(transform(argument)), end = unicode_to_jelly(end)) 1341 | sys.stdout.flush() 1342 | return argument 1343 | 1344 | def zip_ragged(array): 1345 | return jellify(map(lambda t: filter(None.__ne__, t), itertools.zip_longest(*map(iterable, array)))) 1346 | 1347 | atoms = { 1348 | "³": attrdict( 1349 | arity = 0, 1350 | call = lambda: 100 1351 | ), 1352 | "⁴": attrdict( 1353 | arity = 0, 1354 | call = lambda: 16 1355 | ), 1356 | "⁵": attrdict( 1357 | arity = 0, 1358 | call = lambda: 10 1359 | ), 1360 | "⁶": attrdict( 1361 | arity = 0, 1362 | call = lambda: " " 1363 | ), 1364 | "⁷": attrdict( 1365 | arity = 0, 1366 | call = lambda: "\n" 1367 | ), 1368 | "⁸": attrdict( 1369 | arity = 0, 1370 | call = lambda: [] 1371 | ), 1372 | "⁹": attrdict( 1373 | arity = 0, 1374 | call = lambda: 256 1375 | ), 1376 | "A": attrdict( 1377 | arity = 1, 1378 | ldepth = 0, 1379 | call = abs 1380 | ), 1381 | "Ȧ": attrdict( 1382 | arity = 1, 1383 | call = lambda z: int(iterable(z) > [] and all(flatten(z))) 1384 | ), 1385 | "Ạ": attrdict( 1386 | arity = 1, 1387 | call = lambda z: int(all(iterable(z))) 1388 | ), 1389 | "a": attrdict( 1390 | arity = 2, 1391 | ldepth = 0, 1392 | rdepth = 0, 1393 | call = lambda x, y: x and y 1394 | ), 1395 | "ȧ": attrdict( 1396 | arity = 2, 1397 | call = lambda x, y: x and y 1398 | ), 1399 | "ạ": attrdict( 1400 | arity = 2, 1401 | ldepth = 0, 1402 | rdepth = 0, 1403 | call = lambda x, y: abs(x - y) 1404 | ), 1405 | "B": attrdict( 1406 | arity = 1, 1407 | ldepth = 0, 1408 | call = lambda z: to_base(z, 2) 1409 | ), 1410 | "Ḅ": attrdict( 1411 | arity = 1, 1412 | ldepth = 1, 1413 | call = lambda z: from_base(z, 2) 1414 | ), 1415 | "Ḃ": attrdict( 1416 | arity = 1, 1417 | ldepth = 0, 1418 | call = lambda z: z % 2 1419 | ), 1420 | "É": attrdict( 1421 | arity = 1, 1422 | ldepth = 0, 1423 | call = lambda z: 1 - (z % 2) 1424 | ), 1425 | "①": attrdict( 1426 | arity = 1, 1427 | ldepth = 0, 1428 | call = lambda z: functools.reduce(lambda x, y: dyadic_link(atoms["+"], (x, y)), to_base(z, 2), 0) 1429 | ), 1430 | "b": attrdict( 1431 | arity = 2, 1432 | ldepth = 0, 1433 | rdepth = 0, 1434 | call = lambda x, y: to_base(x, y) 1435 | ), 1436 | "ḅ": attrdict( 1437 | arity = 2, 1438 | ldepth = 1, 1439 | rdepth = 0, 1440 | call = lambda x, y: from_base(x, y) 1441 | ), 1442 | "ḃ": attrdict( 1443 | arity = 2, 1444 | ldepth = 0, 1445 | rdepth = 0, 1446 | call = lambda x, y: to_base(x, y, bijective = True) 1447 | ), 1448 | "C": attrdict( 1449 | arity = 1, 1450 | ldepth = 0, 1451 | call = lambda z: 1 - z 1452 | ), 1453 | "Ċ": attrdict( 1454 | arity = 1, 1455 | ldepth = 0, 1456 | call = lambda z: overload((math.ceil, lambda t: t.imag, identity), z) 1457 | ), 1458 | "c": attrdict( 1459 | arity = 2, 1460 | ldepth = 0, 1461 | rdepth = 0, 1462 | call = nCr # noqa N802 1463 | ), 1464 | "ċ": attrdict( 1465 | arity = 2, 1466 | call = lambda x, y: iterable(x).count(y) 1467 | ), 1468 | "ƈ": attrdict( 1469 | arity = 0, 1470 | call = lambda: sys.stdin.read(1) or [] 1471 | ), 1472 | "D": attrdict( 1473 | arity = 1, 1474 | ldepth = 0, 1475 | call = lambda z: to_base(z, 10) 1476 | ), 1477 | "Ḍ": attrdict( 1478 | arity = 1, 1479 | ldepth = 1, 1480 | call = lambda z: from_base(z, 10) 1481 | ), 1482 | "Ḋ": attrdict( 1483 | arity = 1, 1484 | call = lambda z: iterable(z, make_range = True)[1:] 1485 | ), 1486 | "d": attrdict( 1487 | arity = 2, 1488 | ldepth = 0, 1489 | rdepth = 0, 1490 | call = lambda x, y: list(divmod(x, y)) 1491 | ), 1492 | "ḍ": attrdict( 1493 | arity = 2, 1494 | ldepth = 0, 1495 | rdepth = 0, 1496 | call = lambda x, y: int(y % x == 0 if x else y == 0) 1497 | ), 1498 | "ḋ": attrdict( 1499 | arity = 2, 1500 | ldepth = 1, 1501 | rdepth = 1, 1502 | call = lambda x, y: dot_product(x, y, truncate = True) 1503 | ), 1504 | "E": attrdict( 1505 | arity = 1, 1506 | call = equal 1507 | ), 1508 | "Ẹ": attrdict( 1509 | arity = 1, 1510 | call = lambda z: int(any(iterable(z))) 1511 | ), 1512 | "Ė": attrdict( 1513 | arity = 1, 1514 | call = lambda z: [[t + 1, u] for t, u in enumerate(iterable(z))] 1515 | ), 1516 | "e": attrdict( 1517 | arity = 2, 1518 | call = lambda x, y: int(x in iterable(y)) 1519 | ), 1520 | "ẹ": attrdict( 1521 | arity = 2, 1522 | call = lambda x, y: [t + 1 for t, u in enumerate(iterable(x, make_digits = True)) if u == y] 1523 | ), 1524 | "F": attrdict( 1525 | arity = 1, 1526 | call = flatten 1527 | ), 1528 | "Ḟ": attrdict( 1529 | arity = 1, 1530 | ldepth = 0, 1531 | call = lambda z: overload((math.floor, lambda t: t.real, identity), z) 1532 | ), 1533 | "f": attrdict( 1534 | arity = 2, 1535 | call = filter_array 1536 | ), 1537 | "ḟ": attrdict( 1538 | arity = 2, 1539 | call = lambda x, y: filter_array(x, y, False) 1540 | ), 1541 | "G": attrdict( 1542 | arity = 1, 1543 | call = grid 1544 | ), 1545 | "Ġ": attrdict( 1546 | arity = 1, 1547 | call = group 1548 | ), 1549 | "g": attrdict( 1550 | arity = 2, 1551 | ldepth = 0, 1552 | rdepth = 0, 1553 | call = math.gcd 1554 | ), 1555 | "Ɠ": attrdict( 1556 | arity = 0, 1557 | call = lambda: python_eval(input()) 1558 | ), 1559 | "ɠ": attrdict( 1560 | arity = 0, 1561 | call = lambda: jellify(input(), dirty = True) 1562 | ), 1563 | "H": attrdict( 1564 | arity = 1, 1565 | ldepth = 0, 1566 | call = lambda z: div(z, 2) 1567 | ), 1568 | "Ḥ": attrdict( 1569 | arity = 1, 1570 | ldepth = 0, 1571 | call = lambda z: z * 2 1572 | ), 1573 | "Ḣ": attrdict( 1574 | arity = 1, 1575 | call = lambda z: next(iter(z), 0) if hasattr(z, '__iter__') else 0 1576 | ), 1577 | "ḣ": attrdict( 1578 | arity = 2, 1579 | rdepth = 0, 1580 | call = lambda x, y: iterable(x)[:y] 1581 | ), 1582 | "I": attrdict( 1583 | arity = 1, 1584 | ldepth = 1, 1585 | call = lambda z: [z[i] - z[i - 1] for i in range(1, len(z))] 1586 | ), 1587 | "Ď": attrdict( 1588 | arity = 1, 1589 | ldepth = 1, 1590 | call = lambda z: [int(z[i] != z[i - 1]) for i in range(1, len(z))] 1591 | ), 1592 | "İ": attrdict( 1593 | arity = 1, 1594 | ldepth = 0, 1595 | call = lambda z: div(1, z) 1596 | ), 1597 | "Ị": attrdict( 1598 | arity = 1, 1599 | ldepth = 0, 1600 | call = lambda z: int(abs(z) <= 1) 1601 | ), 1602 | "J": attrdict( 1603 | arity = 1, 1604 | call = lambda z: list(range(1, len(iterable(z)) + 1)) 1605 | ), 1606 | "i": attrdict( 1607 | arity = 2, 1608 | call = index_of 1609 | ), 1610 | "ḥ": attrdict( 1611 | arity = 2, 1612 | call = jelly_hash 1613 | ), 1614 | "ị": attrdict( 1615 | arity = 2, 1616 | ldepth = 0, 1617 | call = at_index 1618 | ), 1619 | "j": attrdict( 1620 | arity = 2, 1621 | call = join 1622 | ), 1623 | "K": attrdict( 1624 | arity = 1, 1625 | call = lambda z: join(z, " ") 1626 | ), 1627 | "Ḳ": attrdict( 1628 | arity = 1, 1629 | call = lambda z: jellify(split_at(iterable(z), " ")) 1630 | ), 1631 | "k": attrdict( 1632 | arity = 2, 1633 | call = lambda x, y: partition_at(x, y, border = 2) 1634 | ), 1635 | "ḳ": attrdict( 1636 | arity = 2, 1637 | call = lambda x, y: keep(x, y) 1638 | ), 1639 | "L": attrdict( 1640 | arity = 1, 1641 | call = lambda z: len(iterable(z)) 1642 | ), 1643 | "Ḷ": attrdict( 1644 | arity = 1, 1645 | ldepth = 0, 1646 | call = lambda z: list(range(int(z))) 1647 | ), 1648 | "l": attrdict( 1649 | arity = 2, 1650 | ldepth = 0, 1651 | rdepth = 0, 1652 | call = lambda x, y: overload((math.log, cmath.log), x, y) 1653 | ), 1654 | "ḷ": attrdict( 1655 | arity = 2, 1656 | call = lambda x, y: x 1657 | ), 1658 | "M": attrdict( 1659 | arity = 1, 1660 | call = maximal_indices 1661 | ), 1662 | "Ṃ": attrdict( 1663 | arity = 1, 1664 | call = lambda z: min(iterable(z)) if iterable(z) else 0 1665 | ), 1666 | "Ṁ": attrdict( 1667 | arity = 1, 1668 | call = lambda z: max(iterable(z)) if iterable(z) else 0 1669 | ), 1670 | "m": attrdict( 1671 | arity = 2, 1672 | rdepth = 0, 1673 | call = lambda x, y: iterable(x)[::y] if y else iterable(x) + iterable(x)[::-1] 1674 | ), 1675 | "ṁ": attrdict( 1676 | arity = 2, 1677 | call = lambda x, y: mold(iterable(x, make_copy = True), iterable(y, make_copy = True, make_range = True)) 1678 | ), 1679 | "ṃ": attrdict( 1680 | arity = 2, 1681 | ldepth = 0, 1682 | call = base_decompression 1683 | ), 1684 | "N": attrdict( 1685 | arity = 1, 1686 | ldepth = 0, 1687 | call = lambda z: -z 1688 | ), 1689 | "Ṅ": attrdict( 1690 | arity = 1, 1691 | call = lambda z: output(z, end = "\n") 1692 | ), 1693 | "Ṇ": attrdict( 1694 | arity = 1, 1695 | call = lambda z: int(not(z)) 1696 | ), 1697 | "n": attrdict( 1698 | arity = 2, 1699 | ldepth = 0, 1700 | rdepth = 0, 1701 | call = lambda x, y: int(x != y) 1702 | ), 1703 | "O": attrdict( 1704 | arity = 1, 1705 | ldepth = 0, 1706 | call = lambda z: ord(z) if type(z) == str else z 1707 | ), 1708 | "Ọ": attrdict( 1709 | arity = 1, 1710 | ldepth = 0, 1711 | call = lambda z: chr(int(z)) if type(z) != str else z 1712 | ), 1713 | "Ȯ": attrdict( 1714 | arity = 1, 1715 | call = output 1716 | ), 1717 | "o": attrdict( 1718 | arity = 2, 1719 | ldepth = 0, 1720 | rdepth = 0, 1721 | call = lambda x, y: x or y 1722 | ), 1723 | "ọ": attrdict( 1724 | arity = 2, 1725 | ldepth = 0, 1726 | rdepth = 0, 1727 | call = order 1728 | ), 1729 | "ȯ": attrdict( 1730 | arity = 2, 1731 | call = lambda x, y: x or y 1732 | ), 1733 | "P": attrdict( 1734 | arity = 1, 1735 | call = lambda z: functools.reduce(lambda x, y: dyadic_link(atoms["×"], (x, y)), z, 1) if type(z) == list else z 1736 | ), 1737 | "Ṗ": attrdict( 1738 | arity = 1, 1739 | call = lambda z: iterable(z, make_range = True)[:-1] 1740 | ), 1741 | "p": attrdict( 1742 | arity = 2, 1743 | call = lambda x, y: jellify(itertools.product(iterable(x, make_range = True), iterable(y, make_range = True))) 1744 | ), 1745 | "ṗ": attrdict( 1746 | arity = 2, 1747 | rdepth = 0, 1748 | call = lambda x, y: jellify(itertools.product(*([iterable(x, make_range = True)] * y))) 1749 | ), 1750 | "Q": attrdict( 1751 | arity = 1, 1752 | call = unique 1753 | ), 1754 | "R": attrdict( 1755 | arity = 1, 1756 | ldepth = 0, 1757 | call = lambda z: list(range(1, int(z) + 1)) 1758 | ), 1759 | "Ṛ": attrdict( 1760 | arity = 1, 1761 | call = lambda z: iterable(z, make_digits = True)[::-1] 1762 | ), 1763 | "Ṙ": attrdict( 1764 | arity = 1, 1765 | call = lambda z: output(z, transform = jelly_uneval) 1766 | ), 1767 | "r": attrdict( 1768 | arity = 2, 1769 | ldepth = 0, 1770 | rdepth = 0, 1771 | call = lambda x, y: list(range(int(x), int(y) + 1) or range(int(x), int(y) - 1, -1)) 1772 | ), 1773 | "ṙ": attrdict( 1774 | arity = 2, 1775 | rdepth = 0, 1776 | call = rotate_left 1777 | ), 1778 | "ṛ": attrdict( 1779 | arity = 2, 1780 | call = lambda x, y: y 1781 | ), 1782 | "S": attrdict( 1783 | arity = 1, 1784 | call = lambda z: functools.reduce(lambda x, y: dyadic_link(atoms["+"], (x, y)), z, 0) if type(z) == list else z 1785 | ), 1786 | "Ṡ": attrdict( 1787 | arity = 1, 1788 | ldepth = 0, 1789 | call = lambda z: overload((lambda t: (t > 0) - (t < 0), lambda t: t.conjugate()), z) 1790 | ), 1791 | "Ṣ": attrdict( 1792 | arity = 1, 1793 | call = lambda z: sorted(iterable(z, make_digits = True)) 1794 | ), 1795 | "s": attrdict( 1796 | arity = 2, 1797 | rdepth = 0, 1798 | call = lambda x, y: split_fixed(iterable(x, make_range = True), y) 1799 | ), 1800 | "ṡ": attrdict( 1801 | arity = 2, 1802 | rdepth = 0, 1803 | call = lambda x, y: split_rolling(iterable(x, make_range = True), y) 1804 | ), 1805 | "ṣ": attrdict( 1806 | arity = 2, 1807 | call = lambda x, y: jellify(split_at(iterable(x, make_digits = True), y)) 1808 | ), 1809 | "T": attrdict( 1810 | arity = 1, 1811 | call = lambda z: [u + 1 for u, v in enumerate(z) if v] 1812 | ), 1813 | "Ṭ": attrdict( 1814 | arity = 1, 1815 | ldepth = 1, 1816 | call = lambda z: [int(t + 1 in iterable(z)) for t in range(max(iterable(z) or [0]))] 1817 | ), 1818 | "Ṫ": attrdict( 1819 | arity = 1, 1820 | call = lambda z: iterable(z)[-1] if iterable(z) else 0 1821 | ), 1822 | "t": attrdict( 1823 | arity = 2, 1824 | call = lambda x, y: trim(x, iterable(y), left = True, right = True) 1825 | ), 1826 | "ṫ": attrdict( 1827 | arity = 2, 1828 | rdepth = 0, 1829 | call = lambda x, y: iterable(x)[y - 1 :] 1830 | ), 1831 | "ṭ": attrdict( 1832 | arity = 2, 1833 | call = lambda x, y: iterable(y) + [x] 1834 | ), 1835 | "U": attrdict( 1836 | arity = 1, 1837 | ldepth = 1, 1838 | call = lambda z: z[::-1] 1839 | ), 1840 | "Ụ": attrdict( 1841 | arity = 1, 1842 | call = lambda z: sorted(range(1, len(iterable(z)) + 1), key = lambda t: iterable(z)[t - 1]) 1843 | ), 1844 | "V": attrdict( 1845 | arity = 1, 1846 | ldepth = 1, 1847 | call = lambda z: jelly_eval("".join(map(str, z)), []) 1848 | ), 1849 | "Ṿ": attrdict( 1850 | arity = 1, 1851 | call = lambda z: jellify(jelly_uneval(z)) 1852 | ), 1853 | "v": attrdict( 1854 | arity = 2, 1855 | ldepth = 1, 1856 | call = lambda x, y: jelly_eval("".join(map(str, x)), [y]) 1857 | ), 1858 | "W": attrdict( 1859 | arity = 1, 1860 | call = lambda z: [z] 1861 | ), 1862 | "Ẇ": attrdict( 1863 | arity = 1, 1864 | call = windowed_sublists 1865 | ), 1866 | "Ẉ": attrdict( 1867 | arity = 1, 1868 | call = lambda z: [len(iterable(t, make_digits = True)) for t in iterable(z, make_range = True)] 1869 | ), 1870 | "w": attrdict( 1871 | arity = 2, 1872 | call = windowed_index_of 1873 | ), 1874 | "ẇ": attrdict( 1875 | arity = 2, 1876 | call = windowed_exists 1877 | ), 1878 | "X": attrdict( 1879 | arity = 1, 1880 | call = random_int 1881 | ), 1882 | "Ẋ": attrdict( 1883 | arity = 1, 1884 | call = shuffle 1885 | ), 1886 | "x": attrdict( 1887 | arity = 2, 1888 | ldepth = 1, 1889 | call = lambda x, y: rld(zip(x, y if depth(y) else [y] * len(x))) 1890 | ), 1891 | "ẋ": attrdict( 1892 | arity = 2, 1893 | rdepth = 0, 1894 | call = lambda x, y: iterable(x) * int(y) 1895 | ), 1896 | "Y": attrdict( 1897 | arity = 1, 1898 | call = lambda z: join(z, "\n") 1899 | ), 1900 | "Ỵ": attrdict( 1901 | arity = 1, 1902 | call = lambda z: jellify(split_at(iterable(z), "\n")) 1903 | ), 1904 | "Ẏ": attrdict( 1905 | arity = 1, 1906 | call = lambda z: sum(map(iterable, iterable(z)), []) 1907 | ), 1908 | "y": attrdict( 1909 | arity = 2, 1910 | call = translate 1911 | ), 1912 | "Z": attrdict( 1913 | arity = 1, 1914 | call = zip_ragged 1915 | ), 1916 | "Ż": attrdict( 1917 | arity = 1, 1918 | call = lambda z: [0] + iterable(z, make_range = True) 1919 | ), 1920 | "z": attrdict( 1921 | arity = 2, 1922 | call = lambda x, y: jellify(itertools.zip_longest(*map(iterable, x), fillvalue = y)) 1923 | ), 1924 | "ż": attrdict( 1925 | arity = 2, 1926 | call = lambda x, y: zip_ragged([x, y]) 1927 | ), 1928 | "§": attrdict( 1929 | arity = 1, 1930 | ldepth = 1, 1931 | call = sum 1932 | ), 1933 | "Ä": attrdict( 1934 | arity = 1, 1935 | ldepth = 1, 1936 | call = lambda z: list(itertools.accumulate(z)) 1937 | ), 1938 | "Ḿ": attrdict( 1939 | arity = 1, 1940 | ldepth = 1, 1941 | call = lambda z: list(itertools.accumulate(z, max)) 1942 | ), 1943 | "!": attrdict( 1944 | arity = 1, 1945 | ldepth = 0, 1946 | call = Pi 1947 | ), 1948 | "<": attrdict( 1949 | arity = 2, 1950 | ldepth = 0, 1951 | rdepth = 0, 1952 | call = lambda x, y: int(x < y) 1953 | ), 1954 | "≤": attrdict( 1955 | arity = 2, 1956 | ldepth = 0, 1957 | rdepth = 0, 1958 | call = lambda x, y: int(x <= y) 1959 | ), 1960 | "=": attrdict( 1961 | arity = 2, 1962 | ldepth = 0, 1963 | rdepth = 0, 1964 | call = lambda x, y: int(x == y) 1965 | ), 1966 | ">": attrdict( 1967 | arity = 2, 1968 | ldepth = 0, 1969 | rdepth = 0, 1970 | call = lambda x, y: int(x > y) 1971 | ), 1972 | "≥": attrdict( 1973 | arity = 2, 1974 | ldepth = 0, 1975 | rdepth = 0, 1976 | call = lambda x, y: int(x >= y) 1977 | ), 1978 | ":": attrdict( 1979 | arity = 2, 1980 | ldepth = 0, 1981 | rdepth = 0, 1982 | call = lambda x, y: div(x, y, floor = True) 1983 | ), 1984 | ",": attrdict( 1985 | arity = 2, 1986 | call = lambda x, y: [x, y] 1987 | ), 1988 | ";": attrdict( 1989 | arity = 2, 1990 | call = lambda x, y: iterable(x) + iterable(y) 1991 | ), 1992 | "+": attrdict( 1993 | arity = 2, 1994 | ldepth = 0, 1995 | rdepth = 0, 1996 | call = operator.add 1997 | ), 1998 | "_": attrdict( 1999 | arity = 2, 2000 | ldepth = 0, 2001 | rdepth = 0, 2002 | call = operator.sub 2003 | ), 2004 | "×": attrdict( 2005 | arity = 2, 2006 | ldepth = 0, 2007 | rdepth = 0, 2008 | call = operator.mul 2009 | ), 2010 | "÷": attrdict( 2011 | arity = 2, 2012 | ldepth = 0, 2013 | rdepth = 0, 2014 | call = div 2015 | ), 2016 | "%": attrdict( 2017 | arity = 2, 2018 | ldepth = 0, 2019 | rdepth = 0, 2020 | call = modulus 2021 | ), 2022 | "*": attrdict( 2023 | arity = 2, 2024 | ldepth = 0, 2025 | rdepth = 0, 2026 | call = operator.pow 2027 | ), 2028 | "&": attrdict( 2029 | arity = 2, 2030 | ldepth = 0, 2031 | rdepth = 0, 2032 | conv = conv_dyadic_integer, 2033 | call = operator.and_ 2034 | ), 2035 | "^": attrdict( 2036 | arity = 2, 2037 | ldepth = 0, 2038 | rdepth = 0, 2039 | conv = conv_dyadic_integer, 2040 | call = operator.xor 2041 | ), 2042 | "|": attrdict( 2043 | arity = 2, 2044 | ldepth = 0, 2045 | rdepth = 0, 2046 | conv = conv_dyadic_integer, 2047 | call = operator.or_ 2048 | ), 2049 | "~": attrdict( 2050 | arity = 1, 2051 | ldepth = 0, 2052 | conv = conv_monadic_integer, 2053 | call = lambda z: ~z 2054 | ), 2055 | "²": attrdict( 2056 | arity = 1, 2057 | ldepth = 0, 2058 | call = lambda z: z ** 2 2059 | ), 2060 | "½": attrdict( 2061 | arity = 1, 2062 | ldepth = 0, 2063 | call = lambda z: overload((math.sqrt, cmath.sqrt), z) 2064 | ), 2065 | "°": attrdict( 2066 | arity = 1, 2067 | ldepth = 0, 2068 | call = math.radians 2069 | ), 2070 | "¬": attrdict( 2071 | arity = 1, 2072 | ldepth = 0, 2073 | call = lambda z: int(not z) 2074 | ), 2075 | "‘": attrdict( 2076 | arity = 1, 2077 | ldepth = 0, 2078 | call = lambda z: z + 1 2079 | ), 2080 | "’": attrdict( 2081 | arity = 1, 2082 | ldepth = 0, 2083 | call = lambda z: z - 1 2084 | ), 2085 | "«": attrdict( 2086 | arity = 2, 2087 | ldepth = 0, 2088 | rdepth = 0, 2089 | call = min 2090 | ), 2091 | "»": attrdict( 2092 | arity = 2, 2093 | ldepth = 0, 2094 | rdepth = 0, 2095 | call = max 2096 | ), 2097 | "⁼": attrdict( 2098 | arity = 2, 2099 | call = lambda x, y: int(x == y) 2100 | ), 2101 | "⁻": attrdict( 2102 | arity = 2, 2103 | call = lambda x, y: int(x != y) 2104 | ), 2105 | "®": attrdict( 2106 | arity = 0, 2107 | call = lambda: 0 2108 | ), 2109 | "¹": attrdict( 2110 | arity = 1, 2111 | call = identity 2112 | ), 2113 | "ÆA": attrdict( 2114 | arity = 1, 2115 | ldepth = 0, 2116 | call = lambda z: overload((math.acos, cmath.acos), z) 2117 | ), 2118 | "ÆẠ": attrdict( 2119 | arity = 1, 2120 | ldepth = 0, 2121 | call = lambda z: overload((math.cos, cmath.cos), z) 2122 | ), 2123 | "ÆC": attrdict( 2124 | arity = 1, 2125 | ldepth = 0, 2126 | call = lambda z: sympy.ntheory.generate.primepi(z) 2127 | ), 2128 | "ÆĊ": attrdict( 2129 | arity = 1, 2130 | ldepth = 0, 2131 | call = lambda z: int(sympy.functions.combinatorial.numbers.catalan(z)) 2132 | ), 2133 | "Æc": attrdict( 2134 | arity = 1, 2135 | ldepth = 0, 2136 | call = carmichael 2137 | ), 2138 | "ÆD": attrdict( 2139 | arity = 1, 2140 | ldepth = 0, 2141 | call = lambda z: sympy.ntheory.factor_.divisors(z) 2142 | ), 2143 | "ÆḌ": attrdict( 2144 | arity = 1, 2145 | ldepth = 0, 2146 | call = lambda z: sympy.ntheory.factor_.divisors(z)[:-1] 2147 | ), 2148 | "Æd": attrdict( 2149 | arity = 1, 2150 | ldepth = 0, 2151 | call = lambda z: int(sympy.ntheory.factor_.divisor_count(z)) 2152 | ), 2153 | "Æḍ": attrdict( 2154 | arity = 1, 2155 | ldepth = 0, 2156 | call = lambda z: int(sympy.ntheory.factor_.divisor_count(z) - 1) 2157 | ), 2158 | "ÆḊ": attrdict( 2159 | arity = 1, 2160 | ldepth = 2, 2161 | call = determinant 2162 | ), 2163 | "ÆE": attrdict( 2164 | arity = 1, 2165 | ldepth = 0, 2166 | call = to_exponents 2167 | ), 2168 | "ÆẸ": attrdict( 2169 | arity = 1, 2170 | ldepth = 1, 2171 | call = from_exponents 2172 | ), 2173 | "ÆF": attrdict( 2174 | arity = 1, 2175 | ldepth = 0, 2176 | call = lambda z: [[x, y] for x, y in sorted(sympy.ntheory.factor_.factorint(z).items())] 2177 | ), 2178 | "Æe": attrdict( 2179 | arity = 1, 2180 | ldepth = 0, 2181 | call = lambda z: overload((math.exp, cmath.exp), z) 2182 | ), 2183 | "Æf": attrdict( 2184 | arity = 1, 2185 | ldepth = 0, 2186 | call = lambda z: rld(sorted(sympy.ntheory.factor_.factorint(z).items())) 2187 | ), 2188 | "ÆḞ": attrdict( 2189 | arity = 1, 2190 | ldepth = 0, 2191 | call = lambda z: int(sympy.functions.combinatorial.numbers.fibonacci(z)) 2192 | ), 2193 | "Æi": attrdict( 2194 | arity = 1, 2195 | ldepth = 0, 2196 | call = lambda z: [z.real, z.imag] 2197 | ), 2198 | "Æị": attrdict( 2199 | arity = 1, 2200 | ldepth = 1, 2201 | call = lambda z: complex(*z[:2]) 2202 | ), 2203 | "ÆĿ": attrdict( 2204 | arity = 1, 2205 | ldepth = 0, 2206 | call = lambda z: int(sympy.functions.combinatorial.numbers.lucas(z)) 2207 | ), 2208 | "Æl": attrdict( 2209 | arity = 1, 2210 | ldepth = 0, 2211 | call = lambda z: overload((math.log, cmath.log), z) 2212 | ), 2213 | "Æm": attrdict( 2214 | arity = 1, 2215 | ldepth = 1, 2216 | call = lambda z: div(sum(z), len(z)) 2217 | ), 2218 | "Æṁ": attrdict( 2219 | arity = 1, 2220 | ldepth = 1, 2221 | call = median 2222 | ), 2223 | "Æṃ": attrdict( 2224 | arity = 1, 2225 | ldepth = 1, 2226 | call = mode 2227 | ), 2228 | "ÆN": attrdict( 2229 | arity = 1, 2230 | ldepth = 0, 2231 | call = lambda z: sympy.ntheory.generate.prime(z) 2232 | ), 2233 | "Æn": attrdict( 2234 | arity = 1, 2235 | ldepth = 0, 2236 | call = lambda z: sympy.ntheory.generate.nextprime(z) 2237 | ), 2238 | "ÆP": attrdict( 2239 | arity = 1, 2240 | ldepth = 0, 2241 | call = lambda z: int(sympy.isprime(z)) 2242 | ), 2243 | "Æp": attrdict( 2244 | arity = 1, 2245 | ldepth = 0, 2246 | call = lambda z: sympy.ntheory.generate.prevprime(z) 2247 | ), 2248 | "ÆR": attrdict( 2249 | arity = 1, 2250 | ldepth = 0, 2251 | call = lambda z: list(sympy.ntheory.generate.primerange(2, z + 1)) 2252 | ), 2253 | "Ær": attrdict( 2254 | arity = 1, 2255 | ldepth = 1, 2256 | call = lambda z: jellify(from_base(z[::-1], sympy.poly("x")).all_roots()) 2257 | ), 2258 | "Æṛ": attrdict( 2259 | arity = 1, 2260 | ldepth = 1, 2261 | call = lambda z: jellify(sympy.prod(map(sympy.poly("x").__sub__, z)).all_coeffs()[::-1]) 2262 | ), 2263 | "ÆT": attrdict( 2264 | arity = 1, 2265 | ldepth = 0, 2266 | call = lambda z: overload((math.tan, cmath.tan), z) 2267 | ), 2268 | "ÆṬ": attrdict( 2269 | arity = 1, 2270 | ldepth = 0, 2271 | call = lambda z: overload((math.atan, cmath.atan), z) 2272 | ), 2273 | "ÆṪ": attrdict( 2274 | arity = 1, 2275 | ldepth = 0, 2276 | call = lambda z: sympy.ntheory.factor_.totient(z) if z > 0 else 0 2277 | ), 2278 | "Æṭ": attrdict( 2279 | arity = 1, 2280 | ldepth = 2, 2281 | call = lambda z: sum(sum(r[i : i+1]) for i, r in enumerate(z)) 2282 | ), 2283 | "ÆS": attrdict( 2284 | arity = 1, 2285 | ldepth = 0, 2286 | call = lambda z: overload((math.sin, cmath.sin), z) 2287 | ), 2288 | "ÆṢ": attrdict( 2289 | arity = 1, 2290 | ldepth = 0, 2291 | call = lambda z: overload((math.asin, cmath.asin), z) 2292 | ), 2293 | "Æs": attrdict( 2294 | arity = 1, 2295 | ldepth = 0, 2296 | call = lambda z: int(sympy.ntheory.factor_.divisor_sigma(z)) 2297 | ), 2298 | "Æṣ": attrdict( 2299 | arity = 1, 2300 | ldepth = 0, 2301 | call = lambda z: int(sympy.ntheory.factor_.divisor_sigma(z) - z) 2302 | ), 2303 | "Æv": attrdict( 2304 | arity = 1, 2305 | ldepth = 0, 2306 | call = lambda z: len(sympy.ntheory.factor_.factorint(z)) 2307 | ), 2308 | "Ʋ": attrdict( 2309 | arity = 1, 2310 | ldepth = 0, 2311 | call = lambda z: int(isqrt(z) ** 2 == z) 2312 | ), 2313 | "ƽ": attrdict( 2314 | arity = 1, 2315 | ldepth = 0, 2316 | call = isqrt 2317 | ), 2318 | "ư": attrdict( 2319 | arity = 1, 2320 | ldepth = 0, 2321 | call = math.degrees 2322 | ), 2323 | "Æ!": attrdict( 2324 | arity = 1, 2325 | ldepth = 0, 2326 | call = to_factorial_base 2327 | ), 2328 | "Æ¡": attrdict( 2329 | arity = 1, 2330 | ldepth = 1, 2331 | call = from_factorial_base 2332 | ), 2333 | "Æ?": attrdict( 2334 | arity = 1, 2335 | ldepth = 0, 2336 | call = to_primorial_base 2337 | ), 2338 | "Æ¿": attrdict( 2339 | arity = 1, 2340 | ldepth = 1, 2341 | call = from_primorial_base 2342 | ), 2343 | "Œ!": attrdict( 2344 | arity = 1, 2345 | call = lambda z: jellify(itertools.permutations(iterable(z, make_range = True))) 2346 | ), 2347 | "Œ?": attrdict( 2348 | arity = 1, 2349 | ldepth = 0, 2350 | call = pemutation_at_index 2351 | ), 2352 | "Œ¿": attrdict( 2353 | arity = 1, 2354 | call = permutation_index 2355 | ), 2356 | "ŒB": attrdict( 2357 | arity = 1, 2358 | ldepth = 1, 2359 | call = lambda z: bounce(z) 2360 | ), 2361 | "ŒḄ": attrdict( 2362 | arity = 1, 2363 | call = lambda z: bounce(iterable(z, make_range = True)) 2364 | ), 2365 | "ŒḂ": attrdict( 2366 | arity = 1, 2367 | call = is_palindrome 2368 | ), 2369 | "Œb": attrdict( 2370 | arity = 1, 2371 | call = lambda z: partitions(z) if z else [[]] 2372 | ), 2373 | "Œc": attrdict( 2374 | arity = 1, 2375 | rdepth = 0, 2376 | call = lambda z: jellify(itertools.combinations(iterable(z, make_range = True), 2)) 2377 | ), 2378 | "Œċ": attrdict( 2379 | arity = 1, 2380 | rdepth = 0, 2381 | call = lambda z: jellify(itertools.combinations_with_replacement(iterable(z, make_range = True), 2)) 2382 | ), 2383 | "ŒD": attrdict( 2384 | arity = 1, 2385 | ldepth = 2, 2386 | call = diagonals 2387 | ), 2388 | "ŒḌ": attrdict( 2389 | arity = 1, 2390 | ldepth = 2, 2391 | call = from_diagonals 2392 | ), 2393 | "ŒḊ": attrdict( 2394 | arity = 1, 2395 | call = depth 2396 | ), 2397 | "Œd": attrdict( 2398 | arity = 1, 2399 | ldepth = 2, 2400 | call = lambda z: diagonals([r[::-1] for r in z]) 2401 | ), 2402 | "Œḍ": attrdict( 2403 | arity = 1, 2404 | ldepth = 2, 2405 | call = lambda z: [r[::-1] for r in from_diagonals(z)] 2406 | ), 2407 | "ŒĖ": attrdict( 2408 | arity = 1, 2409 | call = lambda z: list(enumerate_md(z)) 2410 | ), 2411 | "Œe": attrdict( 2412 | arity = 1, 2413 | call = lambda z: [t for t in iterable(z, make_range = True)[1::2]] 2414 | ), 2415 | "ŒG": attrdict( 2416 | arity = 1, 2417 | ldepth = 1, 2418 | call = get_request 2419 | ), 2420 | "ŒĠ": attrdict( 2421 | arity = 1, 2422 | call = group_md 2423 | ), 2424 | "ŒH": attrdict( 2425 | arity = 1, 2426 | call = lambda z: split_evenly(iterable(z, make_range = True), 2) 2427 | ), 2428 | "œị": attrdict( 2429 | arity = 2, 2430 | ldepth = 1, 2431 | call = at_index_ndim 2432 | ), 2433 | "ŒJ": attrdict( 2434 | arity = 1, 2435 | call = indices_md 2436 | ), 2437 | "Œl": attrdict( 2438 | arity = 1, 2439 | ldepth = 1, 2440 | call = lambda z: to_case(z, lower = True) 2441 | ), 2442 | "ŒM": attrdict( 2443 | arity = 1, 2444 | call = maximal_indices_md 2445 | ), 2446 | "Œo": attrdict( 2447 | arity = 1, 2448 | call = lambda z: [t for t in iterable(z, make_range = True)[::2]] 2449 | ), 2450 | "ŒP": attrdict( 2451 | arity = 1, 2452 | call = powerset 2453 | ), 2454 | "ŒṖ": attrdict( 2455 | arity = 1, 2456 | call = partitions 2457 | ), 2458 | "Œṗ": attrdict( 2459 | arity = 1, 2460 | ldepth = 0, 2461 | call = lambda z: sorted(integer_partitions(z), key = len, reverse = True) 2462 | ), 2463 | "Œp": attrdict( 2464 | arity = 1, 2465 | call = lambda z: jellify(itertools.product(*[iterable(t, make_range = True) for t in z])) 2466 | ), 2467 | "ŒQ": attrdict( 2468 | arity = 1, 2469 | call = distinct_sieve 2470 | ), 2471 | "ŒR": attrdict( 2472 | arity = 1, 2473 | ldepth = 0, 2474 | call = lambda z: list(range(-abs(int(z)), abs(int(z)) + 1)) 2475 | ), 2476 | "ŒṘ": attrdict( 2477 | arity = 1, 2478 | call = lambda z: jellify(repr(z)) 2479 | ), 2480 | "Œr": attrdict( 2481 | arity = 1, 2482 | ldepth = 1, 2483 | call = rle 2484 | ), 2485 | "Œṙ": attrdict( 2486 | arity = 1, 2487 | ldepth = 2, 2488 | call = rld 2489 | ), 2490 | "Œs": attrdict( 2491 | arity = 1, 2492 | ldepth = 1, 2493 | call = lambda z: to_case(z, swap = True) 2494 | ), 2495 | "ŒT": attrdict( 2496 | arity = 1, 2497 | call = time_format 2498 | ), 2499 | "ŒṬ": attrdict( 2500 | arity = 1, 2501 | ldepth = 2, 2502 | call = untruth_md 2503 | ), 2504 | "ŒṪ": attrdict( 2505 | arity = 1, 2506 | call = lambda z: [t for t, u in enumerate_md(iterable(z)) if u] 2507 | ), 2508 | "Œt": attrdict( 2509 | arity = 1, 2510 | ldepth = 1, 2511 | call = lambda z: to_case(z, title = True) 2512 | ), 2513 | "ŒV": attrdict( 2514 | arity = 1, 2515 | ldepth = 1, 2516 | call = lambda z: python_eval("".join(map(str, z))) 2517 | ), 2518 | "ŒỤ": attrdict( 2519 | arity = 1, 2520 | call = lambda z: sorted(indices_md(iterable(z)), key = lambda t: at_index_ndim(t, iterable(z))) 2521 | ), 2522 | "Œu": attrdict( 2523 | arity = 1, 2524 | ldepth = 1, 2525 | call = lambda z: to_case(z, upper = True) 2526 | ), 2527 | "Œœ": attrdict( 2528 | arity = 1, 2529 | call = odd_even 2530 | ), 2531 | "ℙ": attrdict( 2532 | arity = 1, 2533 | call = partition_lengths 2534 | ), 2535 | "œ?": attrdict( 2536 | arity = 2, 2537 | ldepth = 0, 2538 | call = pemutation_at_index 2539 | ), 2540 | "œ¿": attrdict( 2541 | arity = 2, 2542 | call = lambda x, y: permutation_index([y.index(value) for value in x]) 2543 | ), 2544 | "æ.": attrdict( 2545 | arity = 2, 2546 | ldepth = 1, 2547 | rdepth = 1, 2548 | call = dot_product 2549 | ), 2550 | "æ%": attrdict( 2551 | arity = 2, 2552 | ldepth = 0, 2553 | rdepth = 0, 2554 | call = symmetric_mod 2555 | ), 2556 | "æ*": attrdict( 2557 | arity = 2, 2558 | ldepth = 2, 2559 | rdepth = 0, 2560 | call = lambda x, y: matrix_to_list(sympy.Matrix(x) ** y) 2561 | ), 2562 | "æ×": attrdict( 2563 | arity = 2, 2564 | ldepth = 2, 2565 | rdepth = 2, 2566 | call = lambda x, y: matrix_to_list(sympy.Matrix(x) * sympy.Matrix(y)) 2567 | ), 2568 | "æA": attrdict( 2569 | arity = 2, 2570 | ldepth = 0, 2571 | rdepth = 0, 2572 | call = math.atan2 2573 | ), 2574 | "æR": attrdict( 2575 | arity = 2, 2576 | ldepth = 0, 2577 | rdepth = 0, 2578 | call = primerange 2579 | ), 2580 | "æC": attrdict( 2581 | arity = 2, 2582 | ldepth = 1, 2583 | rdepth = 0, 2584 | call = convolve_power 2585 | ), 2586 | "æc": attrdict( 2587 | arity = 2, 2588 | ldepth = 1, 2589 | rdepth = 1, 2590 | call = convolve 2591 | ), 2592 | "æċ": attrdict( 2593 | arity = 2, 2594 | ldepth = 0, 2595 | rdepth = 0, 2596 | call = lambda x, y: from_base([1] + [0] * len(to_base(x, y)), y) 2597 | ), 2598 | "æḟ": attrdict( 2599 | arity = 2, 2600 | ldepth = 0, 2601 | rdepth = 0, 2602 | call = lambda x, y: from_base([1] + [0] * (len(to_base(x, y)) - 1), y) 2603 | ), 2604 | "æi": attrdict( 2605 | arity = 2, 2606 | ldepth = 0, 2607 | rdepth = 0, 2608 | call = modinv 2609 | ), 2610 | "æị": attrdict( 2611 | arity = 2, 2612 | ldepth = 0, 2613 | rdepth = 0, 2614 | call = complex 2615 | ), 2616 | "æl": attrdict( 2617 | arity = 2, 2618 | ldepth = 0, 2619 | rdepth = 0, 2620 | call = lcm 2621 | ), 2622 | "ær": attrdict( 2623 | arity = 2, 2624 | ldepth = 0, 2625 | rdepth = 0, 2626 | call = round 2627 | ), 2628 | "æp": attrdict( 2629 | arity = 2, 2630 | ldepth = 0, 2631 | rdepth = 0, 2632 | call = lambda x, y: float("%%.%dg"%y%x) 2633 | ), 2634 | "æ«": attrdict( 2635 | arity = 2, 2636 | ldepth = 0, 2637 | rdepth = 0, 2638 | call = shift_left 2639 | ), 2640 | "æ»": attrdict( 2641 | arity = 2, 2642 | ldepth = 0, 2643 | rdepth = 0, 2644 | call = shift_right 2645 | ), 2646 | "œ!": attrdict( 2647 | arity = 2, 2648 | rdepth = 0, 2649 | call = lambda x, y: jellify(itertools.permutations(iterable(x, make_range = True), y)) 2650 | ), 2651 | "œc": attrdict( 2652 | arity = 2, 2653 | rdepth = 0, 2654 | call = lambda x, y: jellify(itertools.combinations(iterable(x, make_range = True), y)) 2655 | ), 2656 | "œċ": attrdict( 2657 | arity = 2, 2658 | rdepth = 0, 2659 | call = lambda x, y: jellify(itertools.combinations_with_replacement(iterable(x, make_range = True), y)) 2660 | ), 2661 | "œẹ": attrdict( 2662 | arity = 2, 2663 | call = lambda x, y: [t for t, u in enumerate_md(iterable(x)) if u == y] 2664 | ), 2665 | "œi": attrdict( 2666 | arity = 2, 2667 | call = index_of_md 2668 | ), 2669 | "œl": attrdict( 2670 | arity = 2, 2671 | call = lambda x, y: trim(x, iterable(y), left = True) 2672 | ), 2673 | "œP": attrdict( 2674 | arity = 2, 2675 | call = lambda x, y: partition_at([int(t + 1 in iterable(x)) for t in range(max(iterable(x) or [0]))], y, border = 0) 2676 | ), 2677 | "œṖ": attrdict( 2678 | arity = 2, 2679 | call = lambda x, y: partition_at([int(t + 1 in iterable(x)) for t in range(max(iterable(x) or [0]))], y) 2680 | ), 2681 | "œp": attrdict( 2682 | arity = 2, 2683 | call = lambda x, y: partition_at(x, y, border = 0) 2684 | ), 2685 | "œṗ": attrdict( 2686 | arity = 2, 2687 | call = partition_at 2688 | ), 2689 | "œr": attrdict( 2690 | arity = 2, 2691 | call = lambda x, y: trim(x, iterable(y), right = True) 2692 | ), 2693 | "œS": attrdict( 2694 | arity = 2, 2695 | call = lambda x, y: time.sleep(overload((float, bool), y)) or x 2696 | ), 2697 | "œs": attrdict( 2698 | arity = 2, 2699 | rdepth = 0, 2700 | call = lambda x, y: split_evenly(iterable(x, make_range = True), y) 2701 | ), 2702 | "œṡ": attrdict( 2703 | arity = 2, 2704 | rdepth = 0, 2705 | call = split_once 2706 | ), 2707 | "œṣ": attrdict( 2708 | arity = 2, 2709 | call = lambda x, y: jellify(split_around(iterable(x, make_digits = True), iterable(y))) 2710 | ), 2711 | "œ&": attrdict( 2712 | arity = 2, 2713 | call = multiset_intersect 2714 | ), 2715 | "œ-": attrdict( 2716 | arity = 2, 2717 | call = multiset_difference 2718 | ), 2719 | "œ^": attrdict( 2720 | arity = 2, 2721 | call = multiset_symdif 2722 | ), 2723 | "œ|": attrdict( 2724 | arity = 2, 2725 | call = multiset_union 2726 | ), 2727 | "Ø0": attrdict( 2728 | arity = 0, 2729 | call = lambda: [0, 0] 2730 | ), 2731 | "Ø1": attrdict( 2732 | arity = 0, 2733 | call = lambda: [1, 1] 2734 | ), 2735 | "Ø2": attrdict( 2736 | arity = 0, 2737 | call = lambda: [2, 2] 2738 | ), 2739 | "Ø.": attrdict( 2740 | arity = 0, 2741 | call = lambda: [0, 1] 2742 | ), 2743 | "ؽ": attrdict( 2744 | arity = 0, 2745 | call = lambda: [1, 2] 2746 | ), 2747 | "Ø+": attrdict( 2748 | arity = 0, 2749 | call = lambda: [1, -1] 2750 | ), 2751 | "Ø-": attrdict( 2752 | arity = 0, 2753 | call = lambda: [-1, 1] 2754 | ), 2755 | "Ø(": attrdict( 2756 | arity = 0, 2757 | call = lambda: list("()") 2758 | ), 2759 | "Ø<": attrdict( 2760 | arity = 0, 2761 | call = lambda: list("<>") 2762 | ), 2763 | "Ø[": attrdict( 2764 | arity = 0, 2765 | call = lambda: list("[]") 2766 | ), 2767 | "Ø{": attrdict( 2768 | arity = 0, 2769 | call = lambda: list("{}") 2770 | ), 2771 | "Ø^": attrdict( 2772 | arity = 0, 2773 | call = lambda: list("/\\") 2774 | ), 2775 | "Ø⁵": attrdict( 2776 | arity = 0, 2777 | call = lambda: 250 2778 | ), 2779 | "Ø⁷": attrdict( 2780 | arity = 0, 2781 | call = lambda: 128 2782 | ), 2783 | "ذ": attrdict( 2784 | arity = 0, 2785 | call = lambda: 360 2786 | ), 2787 | "Ø%": attrdict( 2788 | arity = 0, 2789 | call = lambda: 2 ** 32 2790 | ), 2791 | "ØA": attrdict( 2792 | arity = 0, 2793 | call = lambda: list(str_upper) 2794 | ), 2795 | "ØẠ": attrdict( 2796 | arity = 0, 2797 | call = lambda: list(str_upper + str_lower) 2798 | ), 2799 | "ØB": attrdict( 2800 | arity = 0, 2801 | call = lambda: list(str_digit + str_upper + str_lower) 2802 | ), 2803 | "ØḄ": attrdict( 2804 | arity = 0, 2805 | call = lambda: list("bcdfghjklmnpqrstvwxyz") 2806 | ), 2807 | "ØḂ": attrdict( 2808 | arity = 0, 2809 | call = lambda: list("BCDFGHJKLMNPQRSTVWXYZ") 2810 | ), 2811 | "ØC": attrdict( 2812 | arity = 0, 2813 | call = lambda: list("BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz") 2814 | ), 2815 | "ØD": attrdict( 2816 | arity = 0, 2817 | call = lambda: list(str_digit) 2818 | ), 2819 | "ØH": attrdict( 2820 | arity = 0, 2821 | call = lambda: list(str_digit + "ABCDEF") 2822 | ), 2823 | "ØJ": attrdict( 2824 | arity = 0, 2825 | call = lambda: list(code_page) 2826 | ), 2827 | "ØP": attrdict( 2828 | arity = 0, 2829 | call = lambda: math.pi 2830 | ), 2831 | "ØṖ": attrdict( 2832 | arity = 0, 2833 | call = lambda: list(map(chr, range(32, 127))) 2834 | ), 2835 | "ØQ": attrdict( 2836 | arity = 0, 2837 | call = lambda: [list("QWERTYUIOP"), list("ASDFGHJKL"), list("ZXCVBNM")] 2838 | ), 2839 | "ØV": attrdict( 2840 | arity = 0, 2841 | call = lambda: list("ṘV") 2842 | ), 2843 | "ØW": attrdict( 2844 | arity = 0, 2845 | call = lambda: list(str_upper + str_lower + str_digit + "_") 2846 | ), 2847 | "ØY": attrdict( 2848 | arity = 0, 2849 | call = lambda: list("BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz") 2850 | ), 2851 | "ØỴ": attrdict( 2852 | arity = 0, 2853 | call = lambda: list("bcdfghjklmnpqrstvwxz") 2854 | ), 2855 | "ØẎ": attrdict( 2856 | arity = 0, 2857 | call = lambda: list("BCDFGHJKLMNPQRSTVWXZ") 2858 | ), 2859 | "Øa": attrdict( 2860 | arity = 0, 2861 | call = lambda: list(str_lower) 2862 | ), 2863 | "Øb": attrdict( 2864 | arity = 0, 2865 | call = lambda: list(str_upper + str_lower + str_digit + "+/") 2866 | ), 2867 | "Øc": attrdict( 2868 | arity = 0, 2869 | call = lambda: list("AEIOUaeiou") 2870 | ), 2871 | "Øe": attrdict( 2872 | arity = 0, 2873 | call = lambda: math.e 2874 | ), 2875 | "Øẹ": attrdict( 2876 | arity = 0, 2877 | call = lambda: list("aeiou") 2878 | ), 2879 | "Øė": attrdict( 2880 | arity = 0, 2881 | call = lambda: list("AEIOU") 2882 | ), 2883 | "Øh": attrdict( 2884 | arity = 0, 2885 | call = lambda: list(str_digit + "abcdef") 2886 | ), 2887 | "Øp": attrdict( 2888 | arity = 0, 2889 | call = lambda: (1 + math.sqrt(5)) / 2 2890 | ), 2891 | "Øq": attrdict( 2892 | arity = 0, 2893 | call = lambda: [list("qwertyuiop"), list("asdfghjkl"), list("zxcvbnm")] 2894 | ), 2895 | "Øv": attrdict( 2896 | arity = 0, 2897 | call = lambda: list("Ṙv") 2898 | ), 2899 | "Øy": attrdict( 2900 | arity = 0, 2901 | call = lambda: list("AEIOUYaeiouy") 2902 | ), 2903 | "Øỵ": attrdict( 2904 | arity = 0, 2905 | call = lambda: list("aeiouy") 2906 | ), 2907 | "Øẏ": attrdict( 2908 | arity = 0, 2909 | call = lambda: list("AEIOUY") 2910 | ) 2911 | } 2912 | 2913 | quicks = { 2914 | "©": attrdict( 2915 | condition = lambda links: links, 2916 | quicklink = lambda links, outmost_links, index: [attrdict( 2917 | arity = links[0].arity, 2918 | call = lambda x = None, y = None: copy_to(atoms["®"], variadic_link(links[0], (x, y))) 2919 | )] 2920 | ), 2921 | "ß": attrdict( 2922 | condition = lambda links: True, 2923 | quicklink = lambda links, outmost_links, index: [create_chain(outmost_links[index])] 2924 | ), 2925 | "¢": attrdict( 2926 | condition = lambda links: True, 2927 | quicklink = lambda links, outmost_links, index: [create_chain(outmost_links[index - 1], 0)] 2928 | ), 2929 | "Ç": attrdict( 2930 | condition = lambda links: True, 2931 | quicklink = lambda links, outmost_links, index: [create_chain(outmost_links[index - 1], 1)] 2932 | ), 2933 | "ç": attrdict( 2934 | condition = lambda links: True, 2935 | quicklink = lambda links, outmost_links, index: [create_chain(outmost_links[index - 1], 2)] 2936 | ), 2937 | "Ñ": attrdict( 2938 | condition = lambda links: True, 2939 | quicklink = lambda links, outmost_links, index: [create_chain(outmost_links[(index + 1) % len(outmost_links)], 1)] 2940 | ), 2941 | "ñ": attrdict( 2942 | condition = lambda links: True, 2943 | quicklink = lambda links, outmost_links, index: [create_chain(outmost_links[(index + 1) % len(outmost_links)], 2)] 2944 | ), 2945 | "¦": attrdict( 2946 | condition = lambda links: len(links) == 2, 2947 | quicklink = lambda links, outmost_links, index: [attrdict( 2948 | arity = max_arity(links + [atoms["¹"]]), 2949 | call = lambda x, y = None: sparse(links[0], (x, y), links[1]) 2950 | )] 2951 | ), 2952 | "¡": attrdict( 2953 | condition = lambda links: len(links) == 2, 2954 | quicklink = lambda links, outmost_links, index: ([links.pop(0)] if len(links) == 2 and links[0].arity == 0 else []) + [attrdict( 2955 | arity = max_arity(links), 2956 | call = lambda x = None, y = None: ntimes(links, (x, y)) 2957 | )] 2958 | ), 2959 | "¿": attrdict( 2960 | condition = lambda links: len(links) == 2, 2961 | quicklink = lambda links, outmost_links, index: [attrdict( 2962 | arity = max(link.arity for link in links), 2963 | call = lambda x = None, y = None: while_loop(links[0], links[1], (x, y)) 2964 | )] 2965 | ), 2966 | "/": attrdict( 2967 | condition = lambda links: links and links[0].arity, 2968 | quicklink = reduce 2969 | ), 2970 | "\\": attrdict( 2971 | condition = lambda links: links and links[0].arity, 2972 | quicklink = reduce_cumulative 2973 | ), 2974 | "ṕ": attrdict( 2975 | condition = lambda links: links and links[0].arity, 2976 | quicklink = prior 2977 | ), 2978 | "Œg": attrdict( 2979 | condition = lambda links: links and links[0].arity, 2980 | quicklink = group_op 2981 | ), 2982 | "Ƒ": attrdict( 2983 | condition = lambda links: links, 2984 | quicklink = lambda links, outmost_links, index: [attrdict( 2985 | arity = max(1, links[0].arity), 2986 | call = lambda x, y = None: int(x == variadic_link(links[0], (x, y))) 2987 | )] 2988 | ), 2989 | "Ṕ": attrdict( 2990 | condition = lambda links: links and links[0].arity, 2991 | quicklink = partition_with 2992 | ), 2993 | "ℙ": attrdict( 2994 | condition = lambda links: links and links[0].arity, 2995 | quicklink = partition_by 2996 | ), 2997 | "ƒ": attrdict( 2998 | condition = lambda links: links and links[0].arity, 2999 | quicklink = foldl 3000 | ), 3001 | "Ɲ": attrdict( 3002 | condition = lambda links: links and not leading_nilad(links), 3003 | quicklink = lambda links, outmost_links, index: [attrdict( 3004 | arity = 1, 3005 | call = lambda z: neighbors(links, z) 3006 | )] 3007 | ), 3008 | "Ƥ": attrdict( 3009 | condition = lambda links: links and links[0].arity, 3010 | quicklink = prefix 3011 | ), 3012 | "ÐƤ": attrdict( 3013 | condition = lambda links: links and links[0].arity, 3014 | quicklink = suffix 3015 | ), 3016 | "ƙ": attrdict( 3017 | condition = lambda links: links and links[0].arity, 3018 | quicklink = lambda links, outmost_links, index: [attrdict( 3019 | arity = 2, 3020 | call = lambda x, y: [monadic_link(links[0], g) for g in split_key(iterable(x, make_digits = True), iterable(y, make_digits = True))] 3021 | )] 3022 | ), 3023 | "ɼ": attrdict( 3024 | condition = lambda links: links, 3025 | quicklink = lambda links, outmost_links, index: [attrdict( 3026 | arity = max(0, links[0].arity - 1), 3027 | call = lambda z = None: copy_to(atoms["®"], variadic_link(links[0], (niladic_link(atoms["®"]), z))) 3028 | )] 3029 | ), 3030 | "Ƭ": attrdict( 3031 | condition = lambda links: links, 3032 | quicklink = lambda links, outmost_links, index: [attrdict( 3033 | arity = links[0].arity, 3034 | call = lambda x = None, y = None: loop_until_loop(links[0], (x, y), return_all = True, vary_rarg = False) 3035 | )] 3036 | ), 3037 | "ƭ": attrdict( 3038 | condition = lambda links: links and ( 3039 | (links[-1].arity == 0 and len(links) - 1 == links[-1].call()) or 3040 | (links[-1].arity and len(links) == 2)), 3041 | quicklink = tie 3042 | ), 3043 | "¤": quickchain(0, 2), 3044 | "$": quickchain(1, 2), 3045 | "Ɗ": quickchain(1, 3), 3046 | "Ʋ": quickchain(1, 4), 3047 | "¥": quickchain(2, 2), 3048 | "ɗ": quickchain(2, 3), 3049 | "ʋ": quickchain(2, 4), 3050 | "#": attrdict( 3051 | condition = lambda links: len(links) == 2, 3052 | quicklink = lambda links, outmost_links, index: ([links.pop(0)] if len(links) == 2 and links[0].arity == 0 else []) + [attrdict( 3053 | arity = max_arity(links), 3054 | call = lambda x = None, y = None: nfind(links, (x, y)) 3055 | )] 3056 | ), 3057 | "?": attrdict( 3058 | condition = lambda links: len(links) == 3, 3059 | quicklink = lambda links, outmost_links, index: [attrdict( 3060 | arity = max(link.arity for link in links), 3061 | call = lambda x = None, y = None: variadic_link(links[0], (x, y)) if variadic_link(links[2], (x, y)) else variadic_link(links[1], (x, y)) 3062 | )] 3063 | ), 3064 | "`": attrdict( 3065 | condition = lambda links: links, 3066 | quicklink = lambda links, outmost_links, index: [attrdict( 3067 | arity = 1, 3068 | call = lambda z: dyadic_link(links[0], (z, z)) 3069 | )] 3070 | ), 3071 | "⁺": attrdict( 3072 | condition = lambda links: links, 3073 | quicklink = lambda links, outmost_links, index: links * 2 3074 | ), 3075 | "С": attrdict( 3076 | condition = lambda links: len(links) == 2, 3077 | quicklink = lambda links, outmost_links, index: ([links.pop(0)] if len(links) == 2 and links[0].arity == 0 else []) + [attrdict( 3078 | arity = max(link.arity for link in links), 3079 | call = lambda x = None, y = None: ntimes(links, (x, y), cumulative = True) 3080 | )] 3081 | ), 3082 | "п": attrdict( 3083 | condition = lambda links: len(links) == 2, 3084 | quicklink = lambda links, outmost_links, index: [attrdict( 3085 | arity = max(link.arity for link in links), 3086 | call = lambda x = None, y = None: while_loop(links[0], links[1], (x, y), cumulative = True) 3087 | )] 3088 | ), 3089 | "Ðe": attrdict( 3090 | condition = lambda links: links, 3091 | quicklink = lambda links, outmost_links, index: [attrdict( 3092 | arity = max(1, links[0].arity), 3093 | call = lambda x, y = None: sparse(links[0], (x, y), range(2, len(x) + 2, 2), indices_literal = True) 3094 | )] 3095 | ), 3096 | "Ðf": attrdict( 3097 | condition = lambda links: links, 3098 | quicklink = lambda links, outmost_links, index: [attrdict( 3099 | arity = links[0].arity, 3100 | call = lambda x, y = None: list(filter(lambda t: variadic_link(links[0], (t, y)), iterable(x, make_range = True))) 3101 | )] 3102 | ), 3103 | "Ðḟ": attrdict( 3104 | condition = lambda links: links, 3105 | quicklink = lambda links, outmost_links, index: [attrdict( 3106 | arity = links[0].arity, 3107 | call = lambda x, y = None: list(itertools.filterfalse(lambda t: variadic_link(links[0], (t, y)), iterable(x, make_range = True))) 3108 | )] 3109 | ), 3110 | "ÐL": attrdict( 3111 | condition = lambda links: links, 3112 | quicklink = lambda links, outmost_links, index: [attrdict( 3113 | arity = links[0].arity, 3114 | call = lambda x = None, y = None: loop_until_loop(links[0], (x, y)) 3115 | )] 3116 | ), 3117 | "ÐĿ": attrdict( 3118 | condition = lambda links: links, 3119 | quicklink = lambda links, outmost_links, index: [attrdict( 3120 | arity = links[0].arity, 3121 | call = lambda x = None, y = None: loop_until_loop(links[0], (x, y), return_all = True) 3122 | )] 3123 | ), 3124 | "ÐḶ": attrdict( 3125 | condition = lambda links: links, 3126 | quicklink = lambda links, outmost_links, index: [attrdict( 3127 | arity = links[0].arity, 3128 | call = lambda x = None, y = None: loop_until_loop(links[0], (x, y), return_loop = True) 3129 | )] 3130 | ), 3131 | "ÐṂ": attrdict( 3132 | condition = lambda links: links, 3133 | quicklink = lambda links, outmost_links, index: [attrdict( 3134 | arity = links[0].arity, 3135 | call = lambda x, y = None: extremes(min, links[0], (x, y)) 3136 | )] 3137 | ), 3138 | "ÐṀ": attrdict( 3139 | condition = lambda links: links, 3140 | quicklink = lambda links, outmost_links, index: [attrdict( 3141 | arity = links[0].arity, 3142 | call = lambda x, y = None: extremes(max, links[0], (x, y)) 3143 | )] 3144 | ), 3145 | "Ðo": attrdict( 3146 | condition = lambda links: links, 3147 | quicklink = lambda links, outmost_links, index: [attrdict( 3148 | arity = max(1, links[0].arity), 3149 | call = lambda x, y = None: sparse(links[0], (x, y), range(1, len(x) + 1, 2), indices_literal = True) 3150 | )] 3151 | ), 3152 | } 3153 | 3154 | hypers = { 3155 | '"': lambda link, none = None: attrdict( 3156 | arity = 2, 3157 | call = lambda x, y: [dyadic_link(link, (u, v)) for u, v in zip(iterable(x), iterable(y))] + iterable(x)[len(iterable(y)) :] + iterable(y)[len(iterable(x)) :] 3158 | ), 3159 | "'": lambda link, none = None: attrdict( 3160 | arity = link.arity, 3161 | call = lambda x = None, y = None: variadic_link(link, (x, y), flat = True, lflat = True, rflat = True) 3162 | ), 3163 | "@": lambda link, none = None: attrdict( 3164 | arity = 2, 3165 | call = lambda x, y: dyadic_link(link, (y, x)) 3166 | ), 3167 | "{": lambda link, none = None: attrdict( 3168 | arity = 2, 3169 | call = lambda x, y: monadic_link(link, x) 3170 | ), 3171 | "}": lambda link, none = None: attrdict( 3172 | arity = 2, 3173 | call = lambda x, y: monadic_link(link, y) 3174 | ), 3175 | "€": lambda link, none = None: attrdict( 3176 | arity = max(1, link.arity), 3177 | call = lambda x, y = None: [variadic_link(link, (t, y)) for t in iterable(x, make_range = True)] 3178 | ), 3179 | "Þ": lambda link, none = None: attrdict( 3180 | arity = link.arity, 3181 | call = lambda x, y = None: sorted(iterable(x, make_range = True), key=lambda t: variadic_link(link, (t, y))) 3182 | ), 3183 | "þ": lambda link, none = None: attrdict( 3184 | arity = 2, 3185 | call = lambda x, y: [[dyadic_link(link, (u, v)) for u in iterable(x, make_range = True)] for v in iterable(y, make_range = True)] 3186 | ), 3187 | "Ѐ": lambda link, none = None: attrdict( 3188 | arity = max(1, link.arity), 3189 | call = lambda x, y = None: [variadic_link(link, (x, t)) for t in iterable(y, make_range = True)] 3190 | ), 3191 | "£": lambda index, links: attrdict( 3192 | arity = index.arity, 3193 | call = lambda x = None, y = None: niladic_chain(links[(variadic_link(index, (x, y)) - 1) % (len(links) - 1)]) 3194 | ), 3195 | "Ŀ": lambda index, links: attrdict( 3196 | arity = max(1, index.arity), 3197 | call = lambda x, y = None: monadic_chain(links[(variadic_link(index, (x, y)) - 1) % (len(links) - 1)], x) 3198 | ), 3199 | "ŀ": lambda index, links: attrdict( 3200 | arity = 2, 3201 | call = lambda x, y: dyadic_chain(links[(variadic_link(index, (x, y)) - 1) % (len(links) - 1)], (x, y)) 3202 | ) 3203 | } 3204 | 3205 | # Aliases 3206 | 3207 | quicks["Ƈ"] = quicks["Ðf"] 3208 | hypers["Ɱ"] = hypers["Ѐ"] 3209 | atoms ["Ẓ"] = atoms ["ÆP"] 3210 | 3211 | chain_separators = { 3212 | "ø": (0, "", True), 3213 | "µ": (1, "", True), 3214 | ")": (1, "€", True), 3215 | "ð": (2, "", True), 3216 | "ɓ": (2, "", False) 3217 | } 3218 | default_chain_separation = (-1, "", True) 3219 | str_arities = "".join(chain_separators.keys()) 3220 | str_strings = "“[^«»‘’”]*[«»‘’”]?" 3221 | str_charlit = "”." 3222 | str_chrpair = "⁾.." 3223 | str_intpair = "⁽.." 3224 | str_realdec = r"(?:0|-(?![1-9.])|-?\d*\.\d*|-?\d+)" 3225 | str_realnum = str_realdec.join(["(?:", "?ȷ", "?|", ")"]) 3226 | str_complex = str_realnum.join(["(?:", "?ı", "?|", ")"]) 3227 | str_literal = "(?:%s)" % "|".join([str_strings, str_charlit, str_chrpair, str_complex, str_intpair]) 3228 | str_litlist = r"\[*" + str_literal + r"(?:(?:\]*,\[*)" + str_literal + ")*" + r"\]*" 3229 | str_nonlits = "|".join(map(re.escape, list(atoms) + list(quicks) + list(hypers))) 3230 | 3231 | regex_chain = re.compile("(?:^(?:" + str_nonlits + "|" + str_litlist + "| )+|[" + str_arities + "])(?:" + str_nonlits + "|" + str_litlist + "| )*") 3232 | regex_liter = re.compile(str_literal) 3233 | regex_token = re.compile(str_nonlits + "|" + str_litlist) 3234 | regex_flink = re.compile("(?=.)(?:[" + str_arities + "]|" + str_nonlits + "|" + str_litlist + "| )*¶?") 3235 | --------------------------------------------------------------------------------