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
# creates a spiral of numbers in a matrix NxN | |
from copy import copy | |
def vortex(n): | |
i = 1 | |
row = [0] * n | |
matrix = [copy(row) for _ in range(n)] | |
pos_row = 0 |
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
President of Ukraine Avtodiy Dormidontovych Kromyeshnyy was crazy. | |
That means he wasn`t inadequate fool - but persistent paranoid. | |
It is as nothing had harmed if a potential fad of variatsko`s hospital A.D. Kromyeshnoho not suffered all Ukraine. | |
Immediatly after the inauguration of President-elect, then more or less mentally healthy person, according to tradition, decided to find out about his future. | |
For this he turned not to the astrologers, not to diviners, not the wizards, as did his predecessors, and - to fashion a professor of occult sciences, a magician and mystic, linguist and Bible scholars, Playboy and Player A. Cop-Aum. | |
The professor at that time was relatively young, irresponsible and for laughing predicted newly elected for A.D.Kromyeshnom long and happy Presidency, but warned of jewelry made of gold, they hiding death for Kromyeshniy. | |
Since that moment the President went crazy. | |
First, he ordered to everyone of his surroundings, begining with office chief and ending with maid, immediately to ge |
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 log, e, copysign | |
def div(x, y): | |
""" divide x by y without using / operator | |
""" | |
sign = x * y | |
res = e ** (log(abs(x)) - log(abs(y))) | |
res = copysign(res, sign) | |
rounded = int(round(res)) | |
if rounded * y == x: |
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
# make port available for your main machine | |
vagrant halt | |
# edit Vagrantfile, to line 72 (near other port forwarding stuff) add: | |
` config.vm.network :forwarded_port, guest: 8120, host: 8120` | |
vagrant up | |
# installing and starting API service | |
sudo su edxapp | |
pip install virtualenvwrapper | |
source virtualenvwrapper.sh |
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 cube_root(x): | |
# negative number cannot be raised to a fractional power | |
res = math.copysign(abs(x) ** (1.0/3), x) | |
# 64 ** (1/3.0) gives us 3.9999999999999996 | |
# and it breaks things up pretty bad. let's try finding int one | |
rounded_res = int(round(res)) | |
if rounded_res ** 3 == x: | |
res = rounded_res |
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
# https://codility.com/demo/take-sample-test/array_inversion_count | |
import bisect | |
def solution(A): | |
""" computes the number of inversions in A, or returns -1 if it exceeds 1,000,000,000 | |
""" | |
# the idea is to store elements left of n-th sorted, | |
# which would allow us to easily find the number of them greater than n-th. | |
sorted_left = [] | |
res = 0 |
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
#!/usr/bin/env python | |
from datetime import date, timedelta | |
import urllib, os | |
day = date(2000,1,17) # the first day | |
while day <= date.today(): | |
name = day.strftime("%Y-%m-%d") + '.gif' | |
if not os.path.isfile(name): |
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 operator import attrgetter | |
from django.db import models | |
class DiligentQuerySet(models.query.QuerySet): | |
""" | |
Represents a QuerySet that allows filtering with lambdas, | |
and sorting on object properties. | |
""" | |
def __init__(self, *args, **kwargs): | |
self._custom_filters = [] |