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 fizzbuzz (n): | |
fizz = n % 3 == 0 | |
buzz = n % 5 == 0 | |
if fizz and buzz: | |
return "FizzBuzz" | |
elif fizz: | |
return "Fizz" | |
elif buzz: | |
return "Buzz" |
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
// utility/util/mem_bench.hpp | |
// Copyright (C) 2017 Seiji Emery | |
// | |
// Memory + time benchmarking code: this hijacks (overloads) global new / delete | |
// to trace memory allocations (very simple: # of allocations / frees + # bytes | |
// allocated / freed), and adds a global variable that displays this stuff | |
// from its dtor (guaranteed to be called after main() but before program exits). | |
// | |
// It also adds basic time profiling (global ctor / dtor) using std::chrono. | |
// |
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
// | |
// Property declaration macros: makes semantics clearer (and saves typing) | |
// | |
#define DECL_PROP_GET(name,type) type name () const | |
#define DECL_PROP_SET(name,type) This& name (type) | |
#define DECL_PROP_GET_VIRTUAL(name,type) virtual DECL_PROP_GET(name,type) = 0; | |
#define DECL_PROP_SET_VIRTUAL(name,type) virtual DECL_PROP_SET(name,type) = 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 TypeInfo; | |
class InputRange; | |
class OutputRange; | |
class IORange; | |
class IObject { | |
public: | |
virtual ~IObject {} | |
virtual const TypeInfo& typeinfo () = 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
# Pseudo code. mix of python, lisp, and haskell syntax | |
# Wrote for fun after skimming https://en.wikipedia.org/wiki/Rubik%27s_Cube_group | |
# and http://www.math.harvard.edu/~jjchen/docs/Group%20Theory%20and%20the%20Rubik%27s%20Cube.pdf | |
# Solve a rubik's cube: | |
def RC-pre-solve (init-state, operations) | |
let solutions = {}, todo = [ (init-state, []) ] | |
# Algorithm is simple: |
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 Matrix (T): | |
class M: | |
def __init__ (self, *args): | |
if (type(args[0]) == type(self)): | |
self.rows = [ [ x for x in row ] for row in args[0].rows ] | |
elif type(args[0] == str): | |
self.rows = [ map(T, row.strip().split()) for row in args[0].strip().split('\n') ] | |
else: | |
self.rows = [ map(T, row) for row in args[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
#pragma once | |
template <typename T> | |
class Queue { | |
// Internal structure: singly linked list, with head + tail pointers | |
struct Node { | |
T value; | |
Node* next = nullptr; |
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
# Author: Seiji Emery | |
# from https://en.wikipedia.org/wiki/Poisson_distribution | |
# | |
# Note: uses the obvious recurrence relation | |
# P(0) = exp(-lambda) | |
# P(k) = P(k - 1) * lambda / k, k > 0 | |
# Which is equivalent to, but much clearer than using factorials imo. | |
from math import exp |
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
// | |
// Memory + time benchmarking code: this hijacks (overloads) global new / delete | |
// to trace memory allocations (very simple: # of allocations / frees + # bytes | |
// allocated / freed), and adds a global variable that displays this stuff | |
// from its dtor (guaranteed to be called after main() but before program exits). | |
// | |
// It also adds basic time profiling (global ctor / dtor) using std::chrono. | |
// | |
// All of this can be achieved externally ofc using time + valgrind (*nix), | |
// and is perhaps preferable - but implementing these interally was an interesting |
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
# | |
# Scaffold, can be trivially extended to do useful things. | |
# Currently, just loads a file + prints # of tris, verts, normals, and uvs. | |
# | |
def load_obj (path): | |
class Parser: | |
def __init__ (self): | |
self.has_tris, self.has_verts, self.has_textures, self.has_normals = False, False, False, False | |
self.tris, self.verts, self.textures, self.normals = [], [], [], [] |