Skip to content

Instantly share code, notes, and snippets.

View ohwang's full-sized avatar
😅

Odin W ohwang

😅
View GitHub Profile
@ohwang
ohwang / gzip_random_test.py
Last active April 16, 2017 01:08
Test gzip compression ratio
# coding: utf-8
import numpy as np
import io
import gzip
import random
np.random.seed(random.randint(1, 1000000))
def get_compression_ratio(data):
@ohwang
ohwang / password_combination.py
Last active December 1, 2016 05:21
how many passwords?
import itertools
"""
Consider we have n sets, each contains n_i elements, sets are disjoint with each other
Q: How many distinct k arrangements are there if we want each of
the n sets to have at least one element in the arrangement ?
"""
using System;
using System.Threading;
using Mono.Unix;
using Mono.Unix.Native;
class Test {
static void Main ()
{
StartHandler();
Console.WriteLine("Press any key to exit...");
class Node(object):
def __init__(self, val):
self.val = val
self.left = None
self.right = None
def __str__(self):
return "(%s|%s|%s)" % (
'*' if self.left else '_',
self.val,
@ohwang
ohwang / bit.py
Created December 29, 2015 23:35
Binary Indexed Tree
class BIT(object):
""" Binary Index Tree
the index starts from 1
"""
def __init__(self, size):
self.size = size
self.xs = [0] * (size + 1)
self.data = [0] * (size + 1)
@ohwang
ohwang / euclidean_algo.py
Created August 23, 2015 14:42
Euclidean Algorithm
# coding: utf-8
import sys
def gcd_rec(x, y):
if x < y:
x, y = y, x
rem = x % y
div = x / y
if rem == 0:
-- from hackerrank.com
-- https://www.hackerrank.com/challenges/common-child
-- define child to be a (not necessarily continuous) substring
-- find the longest sub-child of two strings
import Control.Monad
import Debug.Trace
-- haskell will not do memoization for you
namespace ohw.algo.practice
module Party =
open System.IO
open System.Collections.Generic
let getinput (reader : StreamReader) =
let n = reader.ReadLine() |> int
let rec readRem n =
if n > 0 then
from collections import defaultdict
def solvejam(inputhandle, solve, sep = ' ', finname = 'input.txt'):
fin = open(finname)
fout = open('output.txt', 'w')
N = int(fin.readline())
for casei in range(1, N + 1):
res = solve(*inputhandle(fin))
print("Case #%d:%s%s" % (casei, sep, res))
print("Case #%d:%s%s" % (casei, sep, res), file=fout)