This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def merge_sort(massiv1, massiv2): | |
i = 0 | |
j = 0 | |
merged_list = [] | |
while i < len(massiv1) and j < len(massiv2): | |
if massiv1[i] <= massiv2[j]: | |
merged_list.append(massiv1[i]) | |
i += 1 | |
else: | |
merged_list.append(massiv2[j]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def computeLPSArray(pattern): | |
""" | |
Computes the LPS (Longest Proper Prefix which is also a Suffix) array | |
for the given pattern. | |
Time Complexity: O(M), where M is the length of the pattern. | |
""" | |
M = len(pattern) | |
lps = [0] * M | |
# Length of the previous longest prefix suffix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_even(digit, num_zeroes): | |
# The arguments encode a number that only has one non-zero digit, the first: | |
# - digit: the most significant digit (1..9) | |
# - num_zeroes: the count of trailing zeroes | |
# Returns the count of numbers less than this encoded number that have at | |
# least one even digit | |
return (10**num_zeroes * digit # count all numbers | |
# exclude numbers with fewer digits and only odd digits: | |
- ((5**(num_zeroes+1)-1)//4-1) | |
# exclude numbers with same digit count and only odd digits, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buttonEqual.setOnClickListener(v -> { | |
process = textViewInput.getText().toString(); | |
process = process.replaceAll("×", "*"); | |
process = process.replaceAll("%", "/100"); | |
process = process.replaceAll("÷", "/"); | |
Context rhino = Context.enter(); | |
rhino.setOptimizationLevel(-1); |