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 is_matching(cand): | |
"""Parses a composite `cand` and check if the string matches | |
the pattern. E.g., | |
cand = "++$*+*{2} xm4cccdvv" -> True. | |
`cand` is a pattern and a string separated by a space. Each "+" | |
in the pattern means an alphabetic character in the string; each | |
"$" means a numeric character (1-9); each "*" means an alphabetic | |
character repeated N times with N >= 1 if it is followed by "{N}" | |
and otherwise an alphabetic character repeated 3 times. | |
""" |
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
/* Credibility Index | |
My friend Amin asked me if it was possible to find how good an opinion leader | |
any online person is. It is! | |
I came up with this algorithm: for each (user, context) grouping, find the mean | |
popularity of that grouping. Using this, compute a credibility score. Then, for | |
each user, find the minimum of the credibility scores across all contexts for | |
that user and assign it as his/her final credibility score (since each chain is | |
as strong as its weakest link). |
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 collatz_gen(start): | |
yield start | |
while start != 1: | |
if start % 2 == 0: | |
start //= 2 | |
else: | |
start = 3 * start + 1 | |
yield start | |
for item in collatz_gen(27): |
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
# simpler case of decorators | |
# memoization with decorator | |
def memoize(func): | |
cache = {} | |
def wrapper(*args, **kwargs): | |
if args not in cache: | |
cache[args] = func(*args, **kwargs) | |
return cache[args] |
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
class It: | |
"""An example of iterators.""" | |
def __init__(self, max_, start=1, increment=1): | |
self.max_ = max_ | |
self.start = start | |
self.increment = increment | |
self.counter = self.start - self.increment | |
def __iter__(self): |
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 gen_fun(num): | |
counter = 1 | |
while counter <= num: | |
yield counter | |
counter += 1 | |
for n in gen_func(100): | |
print(n) |
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
const frame = document.querySelector('#frame'); // 10 sheklin divlerini saxlayan cherchive | |
const images = [ | |
// 30 dene shekil | |
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 | |
]; // butun shekiller | |
let imagesOnScreen = images.slice(0, 10); // ekrandaki shekiller, ilk 10 denesi initialize olunur | |
let timeInterval = 1000 + Math.random() * 4000; // 1 saniye ile 5 saniye arasinda bir random interval | |
const locateImagesInDivs = () => { | |
// imagesOnScreen-deki shekilleri #frame-in ichindeki div-lerin ichine yig |
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
"""Reads the amount on a cheque as a string.""" | |
num_sing = ['', 'one ', 'two ', 'three ', 'four ', 'five ', 'six ', 'seven ', | |
'eight ', 'nine ', 'ten ', 'eleven ', 'twelve ', 'thirteen ', | |
'fourteen ', 'fifteen ', 'sixteen ', 'seventeen ', 'eighteen ', | |
'nineteen '] | |
num_tens = ['', 'twenty ', 'thirty ', 'forty ', 'fifty ', 'sixty ', 'seventy ', | |
'eighty ', 'ninety '] |