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 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) |
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
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 |
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 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 |
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
# 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: |
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 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) |
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 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, |
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
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..."); |
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 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 ? | |
""" |
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
# 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): |