def modulus(n): if type(n) == int: return n % 2 else: return -1
Previous Next
import time L = 1 x = 2 y = 3 R = 9 t1 = time.perf_counter() def a(): if L < x ** y <= R: return True t2 = time.perf_counter() print(t2 - t1) t3 = time.perf_counter() def b(): if x ** y > L and x ** y <= R: return True t4 = time.perf_counter() print(t4 - t3) t5 = time.perf_counter() def c(): if x ** y in range(L + 1, R + 1): return True t6 = time.perf_counter() print(t6 - t5)
5.131850057605017e-07 1.5395550172814964e-06 1.5395550172815045e-05
bool isCryptSolution(string[] crypt, char[][] solution) { var words = new List<decimal>(); foreach (var word in crypt) { decimal wordsum = 0; for (var ci = 0; ci < word.Length; ci++) foreach (char[] t in solution) { if (word[ci] != t[0]) continue; if (word[0] == t[0] && t[1] == '0' && word.Length != 1) return false; wordsum += Convert.ToInt32(t[1].ToString()) * Convert.ToDecimal(Math.Pow(10, word.Length - 1 - ci)); break; } words.Add(wordsum); } return words[2] == words[0] + words[1]; }