Skip to content

Instantly share code, notes, and snippets.

View samidarko's full-sized avatar

Sami Darko samidarko

View GitHub Profile
twitt = """What's a little DUI on the way to gobble fries with a "friend"? And that playful punch? Total misunderstanding!!"""
from nltk.tokenize import TweetTokenizer
tknzr = TweetTokenizer()
tknzr.tokenize(twitt)
tokens = tknzr.tokenize(twitt)
from nltk.util import everygrams
everygrams(tknzr.tokenize(twitt))
list(everygrams(tknzr.tokenize(twitt)))
tokens
list(set(tokens))
class SingletonIndex(object):
singleton = None
def __new__(cls, *args, **kwargs):
if not cls.singleton:
cls.singleton = object.__new__(SingletonIndex)
return cls.singleton
def __init__(self, path):
self.index = similarities.Similarity.load(path)
@samidarko
samidarko / counting_sort.py
Created April 10, 2018 10:48
counting sort tryout
#!/bin/env python3
from random import randint
def count(src, dest):
for i in src:
dest[i] += 1
def get_int():
@samidarko
samidarko / findDivisors.hs
Last active April 2, 2018 05:58
find divisors of n
findDivisors :: (RealFrac a, Integral b, Floating a) => a -> [b]
findDivisors n = fn (truncate . sqrt $ n)
where
n' = truncate n
fn i
| i == 1 = 1:n':[]
| n' `mod` i == 0 = let n_by_i = (n' `div` i)
in if n_by_i == i then i : fn next
else i : n_by_i : fn next
100000 92747
9044 3135 7604 4793 8 4704 3565 8545 9328 4186 3940 7003 3531 1093 7494 8593 3779 3062 3038 7007 4804 7582 8835 1814 7682 3671 4491 449 6791 9992 5308 4734 418 2939 9479 4395 9797 4555 8701 482 6156 356 3596 7854 2917 7923 8992 3329 9740 2412 58 9104 8862 1426 2907 4887 570 5730 3214 4234 3680 193 5865 7798 8086 3925 6748 7265 7359 1309 6462 8645 1380 7345 6822 9199 9300 8943 2795 8452 6556 2755 3330 3044 8271 5095 5883 2678 8691 8963 3184 6300 9485 1450 7206 5260 2625 2032 4343 4758 5812 4781 9417 5386 7447 2411 8533 2997 1036 4485 6019 9419 6821 9704 1637 8434 512 8341 9908 495 7213 792 5915 8500 8160 5677 5763 203 7531 4142 7214 7863 9918 3679 8138 1824 2382 502 9837 107 9997 5493 3098 1432 8307 1337 153 9405 6462 1451 3149 9823 8013 6025 2172 6348 6836 1892 2473 1124 2873 9919 3792 6741 2699 9244 2567 2439 3603 6157 1154 3163 5282 2009 1496 78 9596 8543 317 814 1666 222 3397 8865 4512 4940 3991 8566 2537 8732 6693 2371 7323 3086 419 1102 1158 9978 1500 5715 7377 4131 7820 7822 3437 8559 9632
main :: IO ()
main = do
n_k <- getLine
let n_k_a = map read (words "4 1") :: [Int]
let k = n_k_a !! 1
items_temp <- getLine
let items = map read (words items_temp) :: [Int]
b_temp <- getLine
let charged = read b_temp :: Int
let actual = (sum items - items !! k) `div` 2
@samidarko
samidarko / isLeapYear.hs
Last active March 18, 2018 12:29
calculate leap yers
isLeapYear y
| y `mod` 4 == 0 = if y `mod` 100 == 0 then (y `mod` 400 == 0) else True
| otherwise = False
@samidarko
samidarko / polygon-area.hs
Created March 14, 2018 05:48
Warning: this code is in progress and only works for triangles
import System.IO
-- lst = processInput ["1043 770","551 990","681 463"]
lst = processInput ["458 695","621 483","877 469","1035 636","1061 825","875 1023","645 1033","
485 853"]
-- area :: [Double] -> Double
area d@(a:b:c:[]) = let s = sum d / 2 in round $ sqrt $ (s * (s-a) * (s-b) * (s-c) )
processInput = map (tuplintfy . words)
import qualified Data.List as L
l1 = [(1, 3), (2, 4), (5, 7), (6, 8), (10, 15)]
l2 = [(6, 8), (1, 9), (2, 4), (4, 7)]
sort' :: Ord b => [(b, b1)] -> [(b, b1)]
sort' = L.sortOn fst
mergeIntervals [] = []
mergeIntervals ((s, e):xs) = fn ((s,e):[]) $ xs