Skip to content

Instantly share code, notes, and snippets.

View Vaguery's full-sized avatar

Bill Tozier Vaguery

View GitHub Profile
@Vaguery
Vaguery / metameta-pushforth.rb
Created March 14, 2015 22:36
pushforth interpreter written in pushforth, running a pushforth interpreter that adds 1+1
# in the context of pushforth-ruby
runner = PushForth.new([[[[]],[:eval,:dup,:car],:while],[[[[]],[:eval,:dup,:car],:while],[[1,1,:add]]]])
trace = 1000.times.collect {runner.step!.stack}
# trace: (at least the first part)
# [[[:eval, :dup, :car], :while], [[]], [[[[]], [:eval, :dup, :car], :while], [[1, 1, :add]]]]
# [[:while], [:eval, :dup, :car], [[]], [[[[]], [:eval, :dup, :car], :while], [[1, 1, :add]]]]
# [[:eval, :dup, :car, [[:eval, :dup, :car], :while], :enlist], [[[[]], [:eval, :dup, :car], :while], [[1, 1, :add]]]]
# [[:dup, :car, [[:eval, :dup, :car], :while], :enlist], [[[:eval, :dup, :car], :while], [[]], [[1, 1, :add]]]]
# [[:car, [[:eval, :dup, :car], :while], :enlist], [[[:eval, :dup, :car], :while], [[]], [[1, 1, :add]]], [[[:eval, :dup, :car], :while], # [[]], [[1, 1, :add]]]]
@Vaguery
Vaguery / winkler-01.clj
Last active August 29, 2015 14:16
Winkler count: proportion of digits > 1 in an integer
(defn count-digits [num] (count (str num)))
(defn count-not-01 [num]
(let [counts (frequencies (re-seq #"\d" (str num)))]
(- 1
(/ (+ (get counts "0" 0)
(get counts "1" 0))
(count-digits num)))))
(count-not-01 118120) ;; => 1/3
@Vaguery
Vaguery / clojush-example.clj
Last active August 29, 2015 14:16
dependency on Clojush interpreter only
(ns lexicase-redux.core)
(use 'midje.sweet
'(clojush interpreter pushstate)
'(clojush.instructions boolean code common numbers random-instructions string char vectors tag zip return input-output))
;; ...
(println (run-push '(1 2 integer_add false true boolean_or "foo bar" string_length) (make-push-state)))
;; prints:
;; #clojush.pushstate.PushState{:exec (), :code nil, :integer (7 3), :float nil, :boolean (true),
@Vaguery
Vaguery / challenge.md
Last active August 29, 2015 14:15
Winkler ZeroesAndOnes

Which Zeroes and Ones?

Peter Winkler, in one of the first puzzles in his excellent Mathematical Puzzles: A Connoisseur's Collection, asks for proof that every positive integer can be multiplied by some (other) integer, and the resulting product will contain only the digits 0 and 1.

As prep for a small project, I'd rather ask you: For each of the first 100 integers (or 1000 if you're ambitious), what is the smallest integer multiplicand which gives a product with only 1 and 0 among its base-10 digits?

Real question for you: How did you find them? Code welcomed, any language.

@Vaguery
Vaguery / kramdown_div_check.markdown
Created February 13, 2015 11:19
kramdown div bug?

General kramdown test

{: option parse_block_html='true'}

1. This is a free-standing paragraph, separated by newlines from its neighbors.

2. This is a div, separated by newlines from its neighbors in the sourcecode.
3. This is a div with an attribute, separated by newlines from its neighbors.
date 2014-12-07

{::options coderay_line_numbers="nil" /}

Making a habit of the "diamond kata"

I noticed the other day that there's been some interest in my social network (specifically in the agile coach clump) about a certain exercise that folks are calling the "diamond kata". I thought I might give it a go as well.

"Noticed" is noteworthy, since what really happened is that in the process of working with Ron on his new website, I saw one of his narratives on the kata pop up, and it caught my attention. Not because I'd been missing the fun of doing code katas; rather, when I glanced at the problem itself, and then glanced at Ron's and peeked at George Dinwiddie's and then Alistair Cockburn's discussions, I was all like, "Hey, this is obviously a Lindenmayer system, not some kind of array thi

@Vaguery
Vaguery / gist:d3167ddb06953876f2e6
Last active August 29, 2015 14:10
Fenced-Code-Markdown.sublime-snippet
<snippet>
<content><![CDATA[
~~~ ${1:lang}
${2}
~~~
]]></content>
<tabTrigger>fen</tabTrigger>
<scope>text.html.markdown</scope>
</snippet>
@Vaguery
Vaguery / gist:f72f8077110d6f1b1f6a
Last active August 29, 2015 14:10
Musing about hypergraph matchings and perfect matchings

graph matchings

Say an (undirected) graph G = {N,E} has N nodes and E edges. A perfect matching of G is a subset M of edges E in which every node in N appears exactly once.

Say an (undorected) hypergraph H = {N,E} has N nodes and E hyperedges. Each hyperedge in E connects some subset N_j of N to another (possibly overlapping, but not empty) subset N_k of N. In other words, each edge in E of the hypergraph connects some subset of nodes to another subset of nodes.

Now this paper, as far as I can tell, defines a perfect matching of the hypergraph H as being a subset M of E one in which every node N appears exactly once.

That feels wrong. Wrong because any given hyperedge is not to be taken as some kind of "union" or "sum" of connections between individual nodes in H, but as a monolithic connection between two subsets of nodes. Within a given hypergraph, a connection between two subsets of N, one containing a node i and

@Vaguery
Vaguery / demo.css
Created September 26, 2014 02:00
Margin floating images without collisions demo
* {
margin: 0;
padding: 0;
}
body {
background-color: lightgray;
}
article {
@Vaguery
Vaguery / demo.css
Created September 25, 2014 18:15
$20 worth of responsive CSS columns, top-aligned
/* just to make everything snug */
* {
margin:0;
padding:0;
}
/* may as well use an li; it could have been divs, articles, any block element */
li {