name | correct guesses | games together | ratio |
---|---|---|---|
Olivia | 3 | 5 | 0.600 |
Kit | 2 | 4 | 0.500 |
razetime | 2 | 5 | 0.400 |
LyricLy | 1 | 5 | 0.200 |
name | correct guesses | games together | ratio |
---|---|---|---|
LyricLy | 2 | 5 | 0.400 |
Kit | 1 | 4 | 0.250 |
razetime | 1 | 5 | 0.200 |
Olivia | 1 | 5 | 0.200 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | #include <stdlib.h> #include <string.h> /* * Fixes for testing program "test12.py": * * Change line 33 to: * obj = "./" + filename[:-2] + ".so" * Because "apt" doesn't have Python with method named "removesuffix" (Newest version I get is 3.6.5) * * Change line 40 to: * entry = lambda p: lib.entry(p.encode ("ASCII")) * Without applying change, strlen doesn't function as documented, returning only 1 */ /* * #define INCLUDE_MAIN * #define DEBUG */ //Only import when program needs it #if defined (INCLUDE_MAIN) || defined (DEBUG) #include <stdio.h> #endif #ifdef DEBUG void print_prog (int *expr, int size) { for (int i = 0; i < size; i++) { //Print character for operator if (i % 2 == 1) { printf ("%c", expr[i]); } //Print number else { printf ("%d", expr[i]); } } //Print end of line printf ("\n"); } #endif // DEBUG int entry (char *prog) { int size = strlen (prog); int *expr = malloc (sizeof (int) * size); //Use 2 for loop instead of 1 so don't have to check modulo to know if number or operator for (int i = 0; i < size; i += 2) { expr[i] = prog[i] - '0'; //Change from graphical character to corresponding number } for (int i = 1; i < size; i += 2) { expr[i] = prog[i]; } while (size > 1) { #ifdef DEBUG print_prog (expr, size); #endif // DEBUG //Find operation to calculate now int oper = size - 2; int oper_symbol = expr[oper]; for (int i = size - 4; i > 0; i -= 2) { int current_oper_symbol = expr[i]; //Cache it if (oper_symbol == '+' || oper_symbol == '-' || current_oper_symbol == '*' || current_oper_symbol == '/') { oper = i; oper_symbol = current_oper_symbol; } } //printf ("位置 %d 字 %c\n",oper,(char)oper_symbol); int a = expr[oper - 1]; int b = expr[oper + 1]; //int result; no longer need it switch (oper_symbol) { case '+': a += b; //Modify "a" instead of using "resutl" variable. Clever! ;) break; case '-': a -= b; break; case '*': a *= b; break; case '/': a /= b; break; } expr[oper - 1] = a; //Move everything back for there to be no gap for (int i = oper; i < size - 1; i++) { expr[i] = expr[i + 2]; } //Expression has undergone shrinking, so update "size" to match size -= 2; } return expr[0]; } #ifdef INCLUDE_MAIN int main (int argc, char **argv) { if (argc < 2) { printf ("Please provide expression to calculate"); return 1; } printf ("%d\n", entry (argv[1])); return 0; } #endif // INCLUDE_MAIN |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Please use an interpreter with interactive input its better thanks +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++.+++++++..++++.--------------.---------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------------------.------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++.----------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------------------------------------------------------------------------------------------------------.. , >+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------.------.++++++++.---------------------------------------------------------------------------.[-]< [->+>+>+<<<] +>------------------------------------------------------------------------------------------------------------------[<->[-]]<[ [-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------------.+++++++++++++++.-----------.+++++++++++++.[-] ] >+>----------------------------------------------------------------------------------------------------------------[<->[-]]<[ [-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------.++++++.++++++++++..----.+++.+.[-] ] >+>-------------------------------------------------------------------------------------------------------------------[<->[-]]<[ [-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---.------------.++++++++.[-] ] ++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------.++++++.-------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++.++++.--------------. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import re # legitimately the simplest solution i could come up with. def entry(haystack, needle): i = 0 regex = re.escape(needle) while not re.match("^" + regex, haystack, flags=re.DOTALL): # oopsie! :3 forgot the flag, here's the fix. i += 1 regex = "." + regex if i == len(haystack): return -1 return i # uncomment to test the program. # a = input().split(" ") # print(entry(a[0], a[1])) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | from json import loads from collections import OrderedDict from re import match from functools import reduce prog = r''' { "main" : { "val" : ["expect val", "inp"], "main": ["and", ["[]", "val", 0], ["not", ["trim left", ["[]", "val", 1]]] ] }, "valid" : ["def", ["s"], ["list", true, "s"]], "invalid" : ["lit", [false, ""]], "expect val" : ["def", ["s"], { "trimmed" : ["trim left", "s"], "main" : ["if", "trimmed", ["match", ["[]", "trimmed", 0], [["{"], ["expect obj", "trimmed"]], [["["], ["expect arr", "trimmed"]], [["\""], ["expect str", "trimmed"]], [["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-"], ["expect by regex", "trimmed", ["lit", "-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?"] ] ], [["t"], ["expect by regex", "trimmed", ["lit", "true"]]], [["f"], ["expect by regex", "trimmed", ["lit", "false"]]], [["n"], ["expect by regex", "trimmed", ["lit", "null"]]], [false, "invalid"] ], "invalid" ] }], "expect by regex" : ["def", ["s", "regex"], { "matched" : ["regex match", "regex", "s"], "main" : ["match", "matched", [[null], "invalid"], [false, ["valid", ["[a:]", "s", ["len", "matched"]]]] ] }], "expect list of" : ["def", ["s", "expect item"], { "matched first" : ["expect item", "s"], "res" : null, "main" : ["if", ["[]", "matched first", 0], ["do", ["set", "s", ["[]", "matched first", 1]], ["loop", ["not", "res"], { "matched comma" : ["expect by regex", ["trim left", "s"], ["lit", ","]], "matched item" : ["expect item", ["[]", "matched comma", 1]], "did match comma" : ["[]", "matched comma", 0], "did match item" : ["[]", "matched item", 0], "main" : ["match", ["list", "did match comma", "did match item"], [[[true, true]], ["set", "s", ["[]", "matched item", 1]]], [[[false, false]], ["set", "res", ["valid", "s"]]], [false, ["set", "res", "invalid"]] ] }], "res" ], ["valid", "s"] ] }], "expect obj" : ["def", "s", { "matched contents" : ["expect list of", ["[a:]", "s", 1], "expect pair"], "s" : ["trim left", ["[]", "matched contents", 1]], "main" : ["if", "s", ["match", ["[]", "s", 0], [["}"], ["valid", ["[a:]", "s", 1]]], [false, "invalid"] ], "invalid" ] }], "expect pair" : ["def", ["s"], { "matched key" : ["expect str", ["trim left", "s"]], "matched colon" : ["expect by regex", ["trim left", ["[]", "matched key", 1]], ["lit", ":"] ], "matched val" : ["expect val", ["[]", "matched colon", 1]], "did match key" : ["[]", "matched key", 0], "did match colon" : ["[]", "matched colon", 0], "did match val" : ["[]", "matched val", 0], "main" : ["if", ["and", "did match key", "did match colon", "did match val"], "matched val", "invalid" ] }], "expect arr" : ["def", "s", { "matched contents" : ["expect list of", ["[a:]", "s", 1], "expect val"], "s" : ["trim left", ["[]", "matched contents", 1]], "main" : ["if", "s", ["match", ["[]", "s", 0], [["]"], ["valid", ["[a:]", "s", 1]]], [false, "invalid"] ], "invalid" ] }], "expect str" : ["def", "s", ["expect by regex", "s", ["lit", "\"(?:[^\"\\\\\\n]|\\\\[\"\\\\/bfnrt]|\\\\u[0-9a-fA-F]{4})*\""] ] ], "trim left" : ["def", ["s"], ["[]", ["expect by regex", "s", ["lit", "\\s*"]], 1] ] } ''' parsed = loads(prog, object_pairs_hook=OrderedDict) ## ¿Por qué no ha sido aceptado el PEP 505? def regex_match(r, s): m = match(r, s) if m: return m.group() fs = { '+' : lambda f, s: f + s, '-' : lambda f, s: f - s, '*' : lambda f, s: f * s, '/' : lambda f, s: f / s, '=' : lambda f, s: f == s, '!=' : lambda f, s: f != s, 'and': lambda *aas: reduce(lambda f, s: f and s, aas, True), 'or': lambda *aas: reduce(lambda f, s: f or s, aas, False), 'not': lambda f: not f, '[]' : lambda v, i: v[i], '[:]' : lambda v, si, ei: v[si:ei], '[a:]' : lambda v, si: v[si:], '[:b]' : lambda v, ei: v[:ei], 'list' : lambda *aas: list(aas), 'len' : lambda v: len(v), 'in' : lambda v, l: v in l, 'regex match': regex_match, } def entry(j): return run(parsed, [{'inp' : j}, fs]) def run(p, ss): ## Diccionario es como let ... in ... if type(p) == OrderedDict: ss = [{}] + ss for k, v in p.items(): if k != 'main': ss[0][k] = run(v, ss) return run(p['main'], ss) ## Lista llama a una función o es una forma especial, que puede ser: ## - Un valor literal (ya que una cadena normal hace referencia a una variable, una lista tiene sintaxis especial, etc.) ## - Una función anónima ## - Un condicional ## - Una expresión 'match', que empareja un valor con el que corresponde ## - Un bucle ## - Un bloque ## - Cambiar el valor de una variable elif type(p) == list: fn = p[0] if fn == 'lit': return p[1] elif fn == 'def': return lambda *aas: run( p[2], [{a : aas[i] for i, a in enumerate(p[1])}] + ss ) elif fn == 'if': if run(p[1], ss): return run(p[2], ss) else: return run(p[3], ss) elif fn == 'match': v = run(p[1], ss) for c, r in p[2:]: if not c or v in c: return run(r, ss) raise 'Expresión \'match\' no encontró un valor correcto' elif fn == 'loop': v = None while run(p[1], ss): v = run(p[2], ss) return v elif fn == 'do': for e in p[1:-1]: run(e, ss) return run(p[-1], ss) elif fn == 'set': v = run(p[2], ss) set(p[1], v, ss) return v else: if False: a = list(map(lambda e: run(e, ss), p[1:])) print([fn] + a, p) return run(fn, ss)(*a) else: return run(fn, ss)(*map(lambda e: run(e, ss), p[1:])) ## Cadena de caracteres devuelve el valor de una variable elif type(p) == str: return get(p, ss) ## Números, booleanos y nulo evaluan a ellos mismos elif type(p) == int or type(p) == float or type(p) == bool or p is None: return p else: raise '¿Cómo?' ## Los 'scopes' van de más interior a más exterior def get(v, ss): for s in ss: if v in s: ## print(v, s[v]) return s[v] def set(v, vv, ss): for s in ss: if v in s: s[v] = vv ## print(v, vv, ss) if __name__ == '__main__': from sys import argv if len(argv) > 1: print(entry(open(argv[1]).read())) else: while True: print(entry(input())) |
1 2 3 4 5 6 7 8 9 10 11 12 13 | q=int(input()) #take an integer fro mstandard input import math whentherootissquare = math.sqrt(5) puregold = ( ( 1 + whentherootissquare ) / 2 ) #really cool numbers sacrednumbers=[0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986,102334155,165580141,267914296,433494437,701408733,1134903170,1836311903,2971215073,4807526976,7778742049,12586269025,20365011074,32951280099,53316291173,86267571272,139583862445,225851433717,365435296162,591286729879,956722026041,1548008755920,2504730781961,4052739537881,6557470319842,10610209857723,17167680177565,27777890035288,44945570212853,72723460248141,117669030460994,190392490709135,308061521170129,498454011879264,806515533049393,1304969544928657,2111485077978050,3416454622906707,5527939700884757,8944394323791464,14472334024676221,23416728348467685,37889062373143906,61305790721611591,99194853094755497,160500643816367088,259695496911122585,420196140727489673,679891637638612258,1100087778366101931,1779979416004714189,2880067194370816120,4660046610375530309,7540113804746346429,12200160415121876738,19740274219868223167,31940434634990099905,51680708854858323072,83621143489848422977,135301852344706746049,218922995834555169026,354224848179261915075] #that should be enougj honestly lel while q!=0: chosenone = abs(q) if abs(q) < 2 else round(math.log(whentherootissquare * (abs(q)-1/2), puregold)); asignfromabove = [1, -1][q<0]; q -= sacrednumbers[chosenone] * asignfromabove; print(chosenone * asignfromabove,end=" "if q!=0 else"") #https://penis.observer/DDF9D.png :bees: :bees: :bees: :bees: :bees: :BEES: |
post a comment