Skip to content

Instantly share code, notes, and snippets.

board = "RBYYBBRRB"
hand = "YRBGB"
import re
def play(board=list(board+" "), hand=list(hand), trac=[], c=0):
try:
hand[c]
except:
trac.append(["".join(board[:-1]), c])
def format_duration(s):
dt = []
for b, w in [(60, 'second'), (60, 'minute'), (24, 'hour'), (365, 'day'), (s+1, 'year')]:
s, m = divmod(s, b)
if m: dt.append('%d %s%s' % (m, w, 's' * (m > 1)))
return ' and '.join(', '.join(dt[::-1]).rsplit(', ', 1)) or 'now'
import numpy as np
text = "attack postponed untill two am".replace(' ','')
key = 4312567
sliced = [ int(k) for k in str(key) ]
least_cells = lambda x=1: ( x,len(sliced) ) if x*len(sliced) >= len(text) else least_cells(x+1)
text = "attack postponed untill two am".replace(' ','')
key = 4312567
sliced = [ int(k) for k in str(key) ]
#a special function to calculate how many cells at least it would take to store the key and text into a matrix.
least_cells = lambda x=1: x*len(sliced) if x*len(sliced) >= len(text)+len(sliced) else least_cells(x+1)
rows = least_cells() // len(sliced)
matrix = []
text = "hello"
key = "key"
if len(key)<len(text):key=key*(len(text)//len(key)+1) #fix key length if shorter than text.
res = []
for i,j in enumerate(text):
res.append(chr(ord(j)^ord(key[i])))
text = "".join(res)
txt = "Hello".upper()
alpha = [chr(i) for i in range(65, 91)]
res = []
for i in [txt[i:i+3] for i in range(0, len(txt), 3)]:
for x, y in zip([3, 5, 7], i):res.append(alpha[(ord(y)%65+x)%26])
txt = "".join(res)
print("Encryption: "+txt)
txt = "Hello"
alpha = [chr(i) for i in range(65, 91)]
res = []
for i in [txt[i:i+3] for i in range(0, len(txt), 3)]:
for x, y in zip([3, 5, 7], i):res.append(alpha[(ord(y)%65+x)%26])
print("".join(res))
mat = {}
for i in range(5):
for j in range(5):
print((i,j), j+i*5)
mat = {}
for i in range(5):
for j in range(5):
print((i,j), j+i*5)
@ahmed4end
ahmed4end / format.py
Created January 31, 2020 21:29
print beautiful format.
methods = [i for i in dir(str) if not i[0]=="_"]
for i in zip(*[iter(methods)]*4):
print("{:15}{:^15}{:^15}{:>15}".format(*i))