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
| """Пример применения медианного сглаживания для массива t и шириной окна n""" | |
| """ | |
| Вычислительная сложность будет O(n), то есть в нашем случае O(t), чтобы не запутаться в обозначениях. | |
| Мы бежим по массиву из t элементов. Это уже O(t). | |
| В рамках обработки каждого элемента массива, мы или копируем элемент в результирующий массив, то есть обращаемся к нему - это O(1), | |
| либо обращаемся к нескольким последовательным элементам массива. Скажем t[a:b] - имеет вычислительную сложность O(b-a). | |
| Плюс мы создаем новый массив, в котором накапливаем результат. На его создание тоже надо O(t). | |
| Получается, что вся вычислительная сложность алгоритма O(t). Или, если в стандартных терминах, O(n). | |
| """ |
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
| package main | |
| import ( | |
| "encoding/csv" | |
| "fmt" | |
| "os" | |
| "io" | |
| s "strings" | |
| "strconv" | |
| "runtime" |
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
| package main | |
| import ( | |
| "encoding/csv" | |
| "fmt" | |
| "os" | |
| "io" | |
| s "strings" | |
| "strconv" | |
| "runtime" |
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
| # Вторая задача. Вывести числа от 123456 до 654321 в которых встречаются цифры 1..6 по 1 разу. | |
| n = 123456 | |
| while n <= 654321: | |
| s = str(n) # Преобразуем число в строку | |
| h = dict() | |
| # Инициализируем нулями хэш | |
| for i in range(10): |
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 find_prime_numbers(n) | |
| result = [] | |
| array = [false, false] # 0 and 1 is false | |
| (n-1).times{array << true} # 2..n is true | |
| i = 2 | |
| while i*i <= n do | |
| if array[i] | |
| j = i * i | |
| while j <= n do |
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
| func log_info(text string, err interface{}) { | |
| if err == nil { | |
| Info.Printf("%s\n", text) | |
| } else { | |
| Info.Printf(text+" %s\n", err) | |
| } | |
| } | |
| func GetMD5Hash(text string) string { | |
| hasher := md5.New() |
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
| if conn, err := tls.Dial("tcp", servername, tlsconfig); err == nil { | |
| if c, err := smtp.NewClient(conn, host); err == nil { | |
| if err = c.Auth(auth); err == nil { | |
| if err = c.Mail(from.Address); err == nil { | |
| if err = c.Rcpt(to.Address); err == nil { | |
| if w, err := c.Data(); err == nil { | |
| if _, err = w.Write([]byte(message)); err == nil { | |
| if err = w.Close(); err == nil { | |
| if err = c.Quit(); err == nil { | |
| log_info("Письмо отправлено", nil) |
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
| import ( | |
| "crypto/md5" | |
| "encoding/hex" | |
| ) | |
| func GetMD5Hash(text string) string { | |
| hasher := md5.New() | |
| hasher.Write([]byte(text)) | |
| return hex.EncodeToString(hasher.Sum(nil)) | |
| } |
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
| # Reference http://stackoverflow.com/a/18490935/2037928 | |
| # Login as root | |
| # Install needed packages | |
| apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev | |
| cd /tmp | |
| # Download appropriate ruby version https://www.ruby-lang.org/en/downloads/ |
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
| package main | |
| import ( | |
| "log" | |
| "os" | |
| ) | |
| var Error *log.Logger | |
| var Info *log.Logger |
NewerOlder