| ''' | |
| #1 | |
| #1111.1111_2 + 23.32_4 | |
| print(15.9375 + 11.875) | |
| #27.8125 -> 1B.D | |
| #4 | |
| mx = [] | |
| for n in range(1, 1000): | |
| z = n | |
| s = '' | |
| while z > 0: | |
| s = str(z % 2) + s | |
| z //= 2 | |
| if n % 2 == 0: | |
| s += str(z.count('1') % 2) | |
| print(s) | |
| s = (str(bin(sum((list(map(int, str(n).split())))))))[2:] + s | |
| else: | |
| s += '0' | |
| s += (str(bin(sum((list(map(int, str(n).split())))))))[2:] | |
| r = int(s, 2) | |
| if r >= 200: | |
| break | |
| else: | |
| print(n, r) | |
| #5 | |
| def binaryOfFraction(fraction): | |
| binary = str() | |
| while (fraction): | |
| fraction *= 2 | |
| if (fraction >= 1): | |
| int_part = 1 | |
| fraction -= 1 | |
| else: | |
| int_part = 0 | |
| binary += str(int_part) | |
| return binary | |
| def floatingPoint(real_no): | |
| sign_bit = 0 | |
| if(real_no < 0): | |
| sign_bit = 1 | |
| real_no = abs(real_no) | |
| int_str = bin(int(real_no))[2 : ] | |
| fraction_str = binaryOfFraction(real_no - int(real_no)) | |
| ind = int_str.index('1') | |
| exp_str = bin((len(int_str) - ind - 1) + 127)[2 : ] | |
| mant_str = int_str[ind + 1 : ] + fraction_str | |
| mant_str = mant_str + ('0' * (23 - len(mant_str))) | |
| return sign_bit, exp_str, mant_str | |
| sign_bit, exp_str, mant_str = floatingPoint(14.59375) | |
| ieee_32 = str(sign_bit) + exp_str + mant_str | |
| print(ieee_32) | |
| ieee_32 = int(ieee_32, 2) | |
| ieee_32 = hex(ieee_32) | |
| print(ieee_32) | |
| #6 | |
| x = 640 | |
| y = 192 | |
| m = 150 * 1024 * 8 | |
| proz = 2 | |
| color = (m/(x * y)) - proz | |
| print(2 ** color) | |
| #7 | |
| workers = 3000 - 150 | |
| for a in range(10000): | |
| if 800 + 730 + 900 - 90 - 70 - 120 + 2*a == workers: | |
| print(a) | |
| #a = 140 | |
| #8 | |
| p = 157 | |
| q = 733 | |
| e = 17 | |
| def f(p, q): | |
| return (p - 1) * (q - 1) | |
| for d in range(10 ** 5): | |
| if (d*e) % f(p, q) == 1: | |
| print(d) | |
| #10 | |
| print((59 << 1) & (~14 | (133 >> 2))) | |
| #11 | |
| def fn(x, y): | |
| if x == y: | |
| return 1 | |
| if x < y: | |
| return fn(x+2, y) + fn(x+3, y) + fn(x+5, y) | |
| else: | |
| return 0 | |
| print(fn(20, 35)) #если проходит через какое-то число, разделить на две функции | |
| #12 | |
| count = 0 | |
| for s in range(2, 10000, 2): | |
| n = 120 | |
| while s > 0: | |
| s = s // 6 | |
| n = n - 6 | |
| if n == 108: | |
| count += 1 | |
| print(count) | |
| #13 | |
| f = open('11.txt') | |
| s = [int(x) for x in f] | |
| count = 0 | |
| sums = [] | |
| for i in range(1, len(s) - 1): | |
| if s[i] % 8 == 0 and s[i + 1] % 8 == 0: | |
| count += 1 | |
| sums.append(s[i] + s[i + 1]) | |
| print(count) | |
| print(min(sums))''' |