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 f(nth): | |
stack = [0, 1] | |
for _ in range(nth): | |
stack = [stack[1], stack[0]] # swap | |
stack.append(stack[0]) # over | |
stack[1] = stack[1] + stack[2] # + | |
stack.pop() | |
return stack[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
( in this example I use "TOS" to mean "Top of Stack" ) | |
( Here is a one-line word, `f`, that computes the nth fibonacci number. ) | |
: f 0 1 rot 1 ?DO swap over + LOOP swap . ; | |
10 f . ( compute the 10th fibonacci number. ) | |
( `.` pops the computed fibonacci number off the stack and prints it. ) | |
( the stack is empty once 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
class FunctionChain: | |
""" | |
Chains together two or more functions together | |
and returns final result when called. | |
functions: | |
* must be named | |
* must take *exactly one* required argument | |
* ought to have explict return statements | |
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 multiprocessing import Pool | |
import subprocess | |
import sys | |
def run(args): | |
cmd, echo = args | |
process = subprocess.Popen( | |
cmd, |
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 datetime import date, datetime, time | |
class Block: | |
""" | |
Base class to represent a block of time. | |
Instantiation can be like: | |
# Use datetime objects directly |
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 z3 import * | |
""" | |
Generate a 3x3 magic square. | |
Imagine it like so: | |
------------- | |
| a | b | c | | |
------------- |
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 Stack | |
def initialize | |
@contents = [] of Int32 | |
end | |
def pop | |
@contents.pop() | |
end | |
def push(value) |
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
TIILE: gForth Overiew | |
ORIG DATE: 20170930 | |
LAST REV DATE: 20170930 | |
AUTHOR: mj <[email protected]> | |
========================================================== | |
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ | |
========================================================== | |
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 copy import deepcopy | |
class ClausePair: | |
def __init__(self, c1_set, c2_set): | |
self.c1, self.c2 = frozenset(c1_set), frozenset(c2_set) | |
def __eq__(self, other): | |
if isinstance(other, self.__class__): | |
return ((self.c1 == other.c1 and self.c2 == other.c2) or |
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 find_matching_node(expr, matching_fn, parent_node=None, parent_rel=None): | |
if isinstance(expr, Expression) and matching_fn(expr): | |
return (expr, parent_node, parent_rel) | |
if isinstance(expr, Term): | |
return | |
left_match = find_matching_node(expr.left, parent_node=expr, parent_rel='left') | |
right_match = find_matching_node(expr.right, parent_node=expr, parent_rel='right') | |
if left_match: |
NewerOlder