This file contains hidden or 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 PrintParenth: | |
def __init__(self, n): | |
self.n = n | |
self.s = [None for i in range(2*n)] | |
def P(self, l, r): | |
if l==self.n and r==self.n: | |
yield ''.join(self.s) | |
if l < self.n: | |
self.s[l+r] = '(' |
This file contains hidden or 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 strperm(S): | |
if not S: yield "" | |
for c in S: | |
for perm in strperm(S - set([c])): | |
yield c + perm | |
for s in strperm(set("abcd")): | |
print s |
This file contains hidden or 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 C(S,k): | |
'''Choose k elements from set S.''' | |
assert len(S) >= k | |
if k==0: | |
yield set() | |
S1 = S.copy() | |
for s in S: | |
S1.remove(s) | |
if len(S1) >= k-1: | |
for c in C(S1, k-1): |
This file contains hidden or 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.Collections.Generic; | |
namespace ConsoleApplication14 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var A = new int[] { 4, 3, 5, 2 }; |
This file contains hidden or 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 QSort: | |
def __init__(self, A): | |
self.A = A | |
def partition(self, L, U): | |
s = U | |
p = L | |
while s != p: | |
if self.A[p] <= self.A[s]: | |
p += 1 | |
else: |
This file contains hidden or 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.Diagnostics; | |
using System.Collections.Generic; | |
namespace ConsoleApplication4 | |
{ | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> |
This file contains hidden or 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.Text; | |
using System; | |
using System.Diagnostics; | |
namespace ConsoleApplication15 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
This file contains hidden or 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.Collections.Generic; | |
using System.Diagnostics; | |
namespace ConsoleApplication7 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
This file contains hidden or 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
// Deprecated in favor of https://github.com/puzzl3r/puzzles/tree/master/CheckTreeBalance | |
using System.Diagnostics; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace ConsoleApplication8 | |
{ |
This file contains hidden or 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 Queue import Queue | |
def find_path(E, V, n1, n2): | |
"""Find path between n1,n2 of a directed graph""" | |
for n in E: | |
n.from_ = None | |
q = Queue() | |
q.put(n1) | |
found = False | |
while not q.empty(): |