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
| bool p_stmt (SExpr s) { | |
| if (s[0] == "proc") return p_proc(s[1], s[2..$]); | |
| if (s[0] == "enum") return p_enum(s[1], s[2..$]); | |
| if (s[0] == "struct") return p_struct(s[1], s[2..$]); | |
| if (p_data(s)) return true; | |
| return false; | |
| } | |
| bool p_data (SExpr s) { | |
| if (s[0] == "data-string") {} | |
| if (s[0] == "data-array") {} |
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
| ; | |
| ; Would be neat to have enumerable enums like this: | |
| ; | |
| (enum colors | |
| (red 0xff0000ff) | |
| (green 0x00ff00ff) | |
| (blue 0x0000ffff) | |
| (alpha 0x000000ff)) |
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 13 columns, instead of 6 in line 8.
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
| Daily-Max, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec | |
| 1, 2.18(2004), 1.97(1998), 0.85(2009), 12.74(2004), 0.77(2009), 0.16(2011), 0.01(2012), 0.0, 0.05(2000), 0.21(1997), 3.48(2008), 1.39(2012) | |
| 2, 1.04(1998), 4.78(1998), 1.41(2011), 0.77(2006), 1.05(2003), 0.0, 0.0, 0.0, 0.0, 0.02(2016), 1.11(2006), 1.89(2012) | |
| 3, 3.38(2017), 0.98(1998), 1.03(2010), 1.06(2005), 1.02(2003), 0.47(1997), 0.0, 0.0, 0.02(2003), 0.7(2008), 0.66(2008), 3.76(2014) | |
| 4, 1.79(2008), 1.67(2010), 1.02(2016), 1.33(2010), 0.94(2005), 1.29(2011), 0.0, 0.03(2017), 0.0, 1.38(2011), 0.15(2005), 0.61(2014) | |
| 5, 1.75(2016), 2.2(1998), 2.99(2016), 0.09(2006), 2.04(2010), 0.0, 0.0, 0.01(2016), 0.0, 0.46(2006), 1.25(2011), 1.14(2010) | |
| 6, 1.33(2016), 3.85(1999), 1.15(2016), 1.9(2017), 0.04(2003), 0.0, 0.01(2015), 0.01(2013), 0.0, 0.31(2011), 0.27(2003), 2.19(2004) | |
| 7, 2.48(2017), 1.98(2017), 0.27(2006), 1.25(2017), 0.1(2016), 0.0, 0.0, 0.04(2013), 0.0, 0.0, 2.42(2002), 1.37(2004) | |
| 8, 3.49(2017), 1.68(2015), 0.04(2010), 1.09(2005), 3.34(2005) |
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
| ''' Solves the n-queens problem, displaying all solutions as we find them. | |
| Is currently ordered (shows all permutations of queen placements), which is | |
| extremely non-optimal. | |
| Note: this is an original algorithm I worked out on paper fwiw; the core idea | |
| is representing queen placement with 3 1d arrays (not one 2d array), and a | |
| recursive approach where we execute and then unexecute placement operations | |
| to reuse the same memory. |
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
| // | |
| // Observables / behaviors / whatever you want to call these are a pretty simple concept: | |
| // instead of direct variables you operate with functions, and chains that you can mutate | |
| // with more functions. The real work, of course, is in writing a framework / implementation | |
| // that doesn't suck / have terrible performance, since calling 10-20 functions to read one | |
| // variable is not exactly efficient x) | |
| // | |
| // A real library (eg. Rx, React) would have layers of caching and careful engineering that | |
| // this naive implementation does not have. Nevertheless, the core idea is trivial; it's | |
| // building an efficient implementation that's difficult. |
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
| // | |
| // This is a super-crappy, half-finished FRP / reactive library I wrote in JS to work | |
| // through some FRP (Rx) and event dispatching concepts. | |
| // | |
| // This is not real FRP (it's a crappy infinite / unending event stream with some really | |
| // basic higher-order functions), and it's event only; no observables, behavior, push / pull | |
| // (this is push only), etc. | |
| // | |
| // But it was sorta useful as a bit of code to work through some stuff, and it's enough | |
| // code to show really basic input filtering and how to listen and inject events (with |
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 Hanoi: | |
| ''' Constructs an initial-state towers of hanoi problem with n elements. | |
| Each disk is represented by an integer, with biggest = n, smallest = 1. | |
| bottom top | |
| stack[0] = [ n, (n-1), (n-2), ..., 1 ] | |
| stack[1] = [] | |
| stack[2] = [] | |
| ''' |
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
| A few language design ideas, mostly focused on safety + ease of use for mid-to-large sized projects: | |
| 1. New (actually old) method syntax; treat methods as procedures with complex argument semantics, NOT functions (which they generally aren't). | |
| C Syntax: | |
| Result foo (Arg1 arg1, Arg2 arg2, Arg3 arg3) { | |
| int local1 = ...; | |
| double local2 = ...; | |
| } |
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
| ; Transform an x/y point stored in rax w/ a rotation index (0-3) and origin x/y point in rdx. | |
| proc transform_point (in rax pt, in rdx p0, in rcx rot_index) => (out rax pt) | |
| section .data | |
| ; Rotation table: transpose mask + sign-flip mask for x coord. | |
| sign_mask: dd 0x0, 0x0, 0x7000, 0x7000 | |
| ; tr_masks: dq 0x0000ffff, 0xffff0000 ;, 0x0000ffff, 0xffff0000 | |
| tr_masks: dq 0x00000000, 0xffffffff |
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: based on levenshtein2 from https://gist.github.com/SeijiEmery/8ea00d3a33b00a74305c | |
| # which is itself a simple implementation of levenshtein edit distance w/ dynamic programming | |
| # and 2 rows. https://en.wikipedia.org/wiki/Levenshtein_distance | |
| # (Note: the java version was a CS problem in a java class I took a while ago, so no, I didn't | |
| # just copy this from wikipedia, though you might as well since it's literally the same algorithm). | |
| def lev (a, b): | |
| n, m = len(a), len(b) | |
| row, prev = [0] * (n + 1), [0] * (n + 1) | |
| for i in range(n): |