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
| gcc "%1.c" -o "%1.o" && .\"%1.o" < "%1.in" > "%1.log" && fc "%1.log" "%1.out" |
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
| /* 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 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 Integer | |
| def ! | |
| if self > 0 | |
| (1..self).reduce :* | |
| elsif self.zero? | |
| 1 | |
| else | |
| raise ArgumentError, "No factorial for #{self}" | |
| end | |
| end |
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
| 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 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 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 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 DynamicLcs: | |
| def __init__(self): | |
| self.table = {} | |
| @staticmethod | |
| def run(s1, s2): | |
| return DynamicLcs()._run(s1, s2) | |
| def _run(self, s1, s2): |
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 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 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 lcs(s, t): | |
| if not s or not t: | |
| return '' | |
| if s[0] is t[0]: | |
| return s[0] + lcs(s[1:], t[1:]) | |
| result1 = lcs(s[1:], t) | |
| result2 = lcs(s, t[1:]) | |
| if len(result1) > len(result2): | |
| return result1 | |
| 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
| import locale | |
| from math import factorial as f | |
| locale.setlocale(locale.LC_ALL, 'en') | |
| nice = lambda: locale.format("%d", _, grouping=True) |
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
| #include <stdio.h> | |
| #define palsize 100 | |
| /* | |
| * Returns 1 if is a pure palindrome. | |
| * The name is a bit mangled up because good C code shouldn't be understandable. | |
| */ | |
| int ispaldrm(char* s) | |
| { |