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