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
def lcs s1, s2 | |
if s1.empty? or s2.empty? | |
return '' | |
elsif s1[0] == s2[0] | |
return s1[0] + lcs(s1[1..-1], s2[1..-1]) | |
end | |
left = lcs s1[1..-1], s2 | |
right = lcs s1, s2[1..-1] | |
return left.size > right.size ? left : right | |
end |
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 DynamicLcs: | |
def __init__(self): | |
self.table = {} | |
@staticmethod | |
def run(s1, s2): | |
return DynamicLcs()._run(s1, s2) | |
def _run(self, s1, s2): |
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
def add_binary(n, m, c=False): | |
nb = n[-1] == "1" if n else False | |
mb = m[-1] == "1" if m else False | |
r = nb ^ mb ^ c | |
c = not nb and mb and c or nb and (mb or c) | |
n2 = n[:-1] if n else n | |
m2 = m[:-1] if m else m | |
if not n and not m: | |
return "" | |
return add_binary(n2, m2, c) + ("1" if r else "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
farewell = lambda: exit.__call__("Fare well, good lover.") | |
# On Python 2 | |
bravequit2 = lambda: type(exit)("The adventurously brave quitter")("I'll miss you. Please open the console when you be free again.") | |
# On Python 3 | |
bravequit3 = lambda: type(exit)("The adventurously brave quitter", "")("I'll miss you. Please open the console when you be free again.") |
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 Integer | |
def ! | |
if self > 0 | |
(1..self).reduce :* | |
elsif self.zero? | |
1 | |
else | |
raise ArgumentError, "No factorial for #{self}" | |
end | |
end |
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
/* for any stack in the form... */ | |
int _s[100]; | |
int *s = _s; /* top of the pending stack (this location empty) */ | |
/* be very careful about passing expressions for a stack, not well guarded */ | |
#define isempty(s) ((s) - (_s)) | |
#define push(s, v) (*s++ = (v)) | |
#define pop(s) (*(--s)) | |
#define peek(s) ((s)[-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
gcc "%1.c" -o "%1.o" && .\"%1.o" < "%1.in" > "%1.log" && fc "%1.log" "%1.out" |
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
# settings.py | |
APPEND_SLASH = True | |
# projectname/urls.py | |
from django.conf.urls import include | |
from django.conf.urls import patterns | |
from django.conf.urls import url |
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
unsigned int fibonacci(unsigned int n) { | |
if (n > 2) { | |
unsigned int a = 1, b = 1; | |
while (n-- > 2) { | |
b = a + b; | |
a = b - a; | |
} | |
return b; | |
} else if (n) { | |
return 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
Show hidden characters
{ | |
"font_size": 12, | |
"ignored_packages": | |
[ | |
"Vintage" | |
], | |
"translate_tabs_to_spaces": true, | |
"rulers": [80], | |
"remember_open_files": false, | |
"hot_exit": false, |