This file contains 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
import math | |
def sqr(a): | |
return a*a | |
def compute_distance(x1, y1, x2, y2): | |
return math.sqrt(sqr(x2 - x1) + sqr(y2 - y1)) | |
try: | |
fp = open("file.data", "r") |
This file contains 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
from math import * | |
from tkinter import * | |
#Парочка математических функций | |
def sqr(a): | |
return a*a | |
def distance(x, y, x1, y1): | |
return sqrt(sqr(x1 - x) + sqr(y1 - y)) |
This file contains 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
from math import sqrt | |
a, b, c = map(float, input().split()) | |
d = b*b - 4*a*c; | |
if (d >= 0): | |
print("{0:.6f}".format(((-b + sqrt(d)) / (2 * a)))) | |
print("{0:.6f}".format(((-b - sqrt(d)) / (2 * a)))) |
This file contains 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
from math import sqrt | |
def f(a, b, c): | |
d = b*b - 4*a*c; | |
if (d >= 0): | |
return ((-b + sqrt(d)) / (2 * a)), ((-b - sqrt(d)) / (2 * a)) | |
a, b, c, d = map(float, input().split()) |
This file contains 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
#bin_search - бинарный поиск | |
#array- список значений | |
#val - искомое значение | |
#l, r - индексы поиска, r - указывает на следующий за последним элемент | |
#Возвращает индекс элемента и количество итераций, если элемент | |
#не найден, вместо индекса возвращается None | |
def bin_search(array, val, l, r): | |
#Количество итераций |
This file contains 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 line_search(array, val): | |
c = 0 | |
while c < len(array): | |
if (val == array[c]): | |
return (c, c) | |
с += 1 | |
return (None, c) |
This file contains 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
#Оцениваем производительность бинарного поиска на примере сравнения с линейным | |
#Пусть binsearch.py лежит в текущей директории | |
#Ссылка на binserach - https://gist.github.com/rkhapov/c9507eaa2afb1683fcbb | |
from binsearch import bin_search | |
#Пусть linesearch.py лежит в текущей директории | |
#Ссылка на linesearch - https://gist.github.com/rkhapov/f9726978ec001dedf9fc | |
from linesearch import line_search |
This file contains 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
#include <iostream> | |
#include <cstdlib> | |
#include <string> | |
const std::string numbers = "123456789"; | |
int summ = 0; | |
void permuntation(const std::string &source) | |
{ |
This file contains 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
#Мини-модуль для генерации массива случайных чисел | |
from random import randint | |
#size - размер | |
#lower - нижняя граница | |
#upper - верхняя граница | |
def random_array(size, lower, upper): | |
arr = [] |
This file contains 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
#selection sort, 2 реализации | |
#Функция поиска индекса минимального/максимального элемента | |
#array - массив | |
#step - направление шага поиска | |
#beg - ничальная позиция | |
#size - сколько элементов пробежать | |
def find_compare(array, compare, step, beg, size): | |
#Пусть текущим минимальным элементом будет нулевой | |
find_index = beg |
OlderNewer