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
digits = { | |
0: [ | |
' **** ', | |
' * * ', | |
' * * ', | |
' * * ', | |
' * * ', | |
' * * ', | |
' * * ', | |
' * * ', |
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
dic = {0: 0x7e4242424242427e, | |
1: 0x0206020202020202, | |
2: 0x3c4202040810207e, | |
3: 0x3c42020C0202423c, | |
4: 0x02060A123F020202, | |
5: 0x7E40407C0202423c, | |
6: 0x3c42407c4242423c, | |
7: 0x7e02040810101010, | |
8: 0x3c42423c4242423c, | |
9: 0x3c42423e0202423c, |
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
ship = 'd3d9' | |
badship = 'd3e7' | |
def check(ship): | |
x1, y1, x2, y2 = map(lambda (x,y): y(x), zip(ship, (ord,int,ord,int))) | |
return ( | |
check_diagonal(x1, y1, x2, y2) | |
and check_border(x1, y1) | |
and check_border(x2, y2) |
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 str_to_mask(mask): | |
return reduce(lambda x, y: y+(x<<8), map(int, mask.split(".")), 0) | |
def check_ip_mask(mask): | |
while mask & 0x7fffffff: | |
if not mask & 0x40000000: | |
return False | |
mask <<= 1 | |
return True |
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
ships=['a1c1', 'd3d7'] | |
def fire(shot, ship): | |
x, y = shot | |
x1, y1, x2, y2 = ship | |
return x1 <= x <= x2 and int(y1) <= int(y) <= int(y2) | |
print 20*"-" | |
for i in xrange(0,10): | |
for j in xrange(0,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
#!/usr/bin/python | |
""" | |
Предположим, у нас есть access.log веб-сервера. | |
Как с помощью стандартных консольных средств найти десять IP-адресов, | |
от которых было больше всего запросов? | |
А как сделать это с помощью скрипта на Python? | |
""" | |
import sys | |
from collections import Counter |
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
#!/bin/sh | |
sqlite3 -header << EOF | |
CREATE TABLE users (UID int, Name varchar); | |
INSERT INTO users (UID, Name) VALUES (1, "Платон Щукин"); | |
INSERT INTO users (UID, Name) VALUES (2, "Лера Страза"); | |
INSERT INTO users (UID, Name) VALUES (3, "Георгий Атласов"); | |
CREATE TABLE messages (UID int, msg varchar); | |
INSERT INTO messages (UID, msg) VALUES (1, "Привет, Платон!"); |
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
# -*- encoding: utf-8 -*- | |
"""В системе авторизации есть ограничение: логин должен начинаться с | |
латинской буквы, состоять из латинских букв, цифр, точки и минуса, но | |
заканчиваться только латинской буквой или цифрой; минимальная длина | |
логина — один символ, максимальная — 20. Напишите код, проверяющий | |
соответствие входной строки этому правилу. Придумайте несколько | |
способов решения задачи и сравните их.""" | |
def check1(login): | |
if not 1 <= len(login) <= 20: |
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
# -*- encoding: utf-8 -*- | |
def get_dict(keys, values): | |
"""Есть два списка разной длины. В первом содержатся ключи, а во | |
втором значения. Напишите функцию, которая создаёт из этих ключей и | |
значений словарь. Если ключу не хватило значения, в словаре должно | |
быть значение None. Значения, которым не хватило ключей, нужно | |
игнорировать.""" | |
from itertools import imap, ifilter |
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
c=[int(i) for i in input().split()] | |
n=len(c) | |
for i in range(n): | |
right = (i+1)%n | |
left = (i+n-1)%n | |
print(c[left]+c[right], end=' ') |