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
// Created by Seiji Emery on 9/16/14. | |
// Copyright (c) 2014 Seiji Emery. All rights reserved. | |
// | |
// Base class for logic components (logic gates and I/O stuff like buttons and | |
// displays). Defines interface that all of these must implement (boolean internal | |
// state, multiple (0+) inputs, and one output value (retrieved via getState()). | |
// Implementations are stored as a list within the LogicSim class (hence the need | |
// for a uniform interface). | |
class LogicComponent { |
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
// Defines a better type querry function that enables object prototypes to define their own type repr | |
$typeof = function(value) { | |
return value.__proto__.type || typeof(value); | |
} | |
// Switch to 'release' (or any other value) to disable expensive typechecking. | |
releaseMode = 'debug'; |
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 <sstream> | |
// Provides a generic python-inspired string join function that operates on iterators | |
// and containers. | |
template <typename Iterator> | |
string join (const std::string & delim, Iterator begin, Iterator end) { | |
std::ostringstream ss; | |
if (begin != 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
// C++ challenge: implement a string class - specifically this one, which provides most | |
// of basic string operations you'd need to interface w/ other C++ code. | |
// Note: using the stl is cheating (obviously), as much of the challenge here is in | |
// learning how to do low level memory management and pointer arithmetic. | |
class String { | |
public: | |
String (); // Default constructor (construct empty string) | |
String (const char *c_str); // Construct a String type from a c (null terminated) string | |
String (const String &); // Copy constructor |
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 re | |
def bperm (n): | |
""" Returns the permutations of n boolean variables """ | |
if n < 1: | |
return [] | |
if n == 1: | |
return [[True], [False]] | |
vals = bperm(n-1) | |
return [ [True] + v for v in vals ] + [ [False] + v for v in vals ] |
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
enum class NodeType { | |
InactiveNode, | |
AndGate, | |
OrGate, | |
XorGate, | |
NotGate, | |
NandGate, | |
NorGate, | |
Input, // Used for component I/O, and to implement more complicated logic components (buttons, displays, etc) | |
Output |
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
// | |
// type.js | |
// Created by Seiji Emery 5/5/2014 | |
// | |
// Defines (among other things) a class creation facility, a simple type-system | |
// with strong reflective capabilities, and a mechanism for strongly-typed | |
// function overloading (using said type system). | |
// | |
// Disclaimer: None of these are very fast (overloading is implemented by stringifying | |
// types into a a lookup string that pulls stuff out of a dictionary of function |
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 UnitConverter (object): | |
def __init__ (self): | |
self.conv = {} | |
def connect (self, a, b, k): | |
self.conv[a][b] = k | |
self.conv[b][a] = 1.0 / k | |
for c in self.conv[a].keys(): | |
if c != b and c not in self.conv[b].keys(): |
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
Use/implement something similar to lzz (http://www.lazycplusplus.com/), but with some extensions. | |
Main ideas: | |
- only one (.lzz?) file, instead of split header (.h) / implementation (.cpp) files | |
- class methods and friend functions always written inline inside the class (much cleaner/more minimalistic) | |
- use IDE code folding to hide stuff... | |
- script autogenerates the .h and .cpp files for you | |
- build system: | |
- IDEs could be tricky, but getting something to work with cmake or makefiles would be pretty easy... | |
- Alternatively, could implement own build system that autodetects imported local files, and generates makefiles/whatever to process and include them. |
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
-- Note: fib_inf generates an infinite list | |
fib_inf :: Int -> Int -> [Int] | |
fib_inf a b = a : fib_inf b (a+b) | |
-- Which is ok, since Haskell uses lazy evaluation | |
fib_to n = takeWhile (< n) (fib_inf 0 1) | |
is_even x = x `mod` 2 == 0 | |
even_fib_sum = sum . (filter is_even) . fib_to |
OlderNewer