Skip to content

Instantly share code, notes, and snippets.

Igor Shevchenko igor-shevchenko

Block or report user

Report or block igor-shevchenko

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View anagram.hs
import Data.List (deleteFirstsBy, null)
import System.IO.UTF8 (readFile)
anagrams :: [Char] -> [String] -> [String]
anagrams [] _ = [""]
anagrams _ [] = []
anagrams letters dictionary =
let currentWord = head dictionary
remainingLetters = removeWord letters currentWord
newDictionary = filterDictionary remainingLetters dictionary
igor-shevchenko / huffman.hs
Last active Dec 17, 2015
Huffman coding algorithm
View huffman.hs
import Data.List (sort, insert, elem, concat)
data HuffmanTree = Leaf { symbol :: Char, weight :: Int} | Node { left :: HuffmanTree, right :: HuffmanTree, symbols :: [Char], weight :: Int} deriving (Show)
instance Eq HuffmanTree where
tree1 == tree2 = (weight tree1) == (weight tree2)
instance Ord HuffmanTree where
tree1 `compare` tree2 = (weight tree1) `compare` (weight tree2)
View mvartree.hs
import Control.Monad
import Control.Concurrent.MVar
type TreeRef a = MVar (MutableTree a)
data MutableTree a = Node { value :: a, left :: TreeRef a, right :: TreeRef a, parent :: TreeRef a }
| Leaf { value :: a, parent :: TreeRef a}
treeChangeValue :: MutableTree a -> (a -> a) -> MutableTree a
treeChangeValue (Leaf a p) f = Leaf (f a) p
treeChangeValue (Node a l r p) f = Node (f a) l r p
igor-shevchenko /
Created Aug 30, 2013
map and filter defined using reduce
def map_(function, iterable):
return reduce(lambda lst, cur: lst + [function(cur)], iterable, [])
def filter_(function, iterable):
return reduce(lambda lst, cur: ((lst + cur) if type(iterable) is str else (lst + (cur,) if type(iterable) is tuple else lst + [cur])) if (function if function is not None else bool)(cur) else lst, iterable, '' if type(iterable) is str else tuple() if type(iterable) is tuple else [])
igor-shevchenko / pi.c
Created Oct 31, 2013
Distributed Monte Carlo estimation of pi using posix message queue
View pi.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <math.h>
#include <mqueue.h>
#include <sys/stat.h>
#include <errno.h>
# coding: utf-8
from collections import Counter
import networkx as nx
def get_cities():
with open('cities.txt') as f:
for line in f:
yield line.strip().decode('utf8').lower()
View y-cities.txt
igor-shevchenko /
Created May 18, 2017
rutermextract — примеры использования параметров
# Примеры на Python 2.7
from rutermextract import TermExtractor
term_extractor = TermExtractor()
text = u'Съешь еще этих мягких французских булок да выпей же чаю'
for term in term_extractor(text):
print term.normalized
igor-shevchenko /
Created Jun 20, 2013
TextRank algorithm for text summarization.
from itertools import combinations
from nltk.tokenize import sent_tokenize, RegexpTokenizer
from nltk.stem.snowball import RussianStemmer
import networkx as nx
def similarity(s1, s2):
if not len(s1) or not len(s2):
return 0.0
return len(s1.intersection(s2))/(1.0 * (len(s1) + len(s2)))
You can’t perform that action at this time.