Skip to content

Instantly share code, notes, and snippets.

View sirpengi's full-sized avatar

shu.chen sirpengi

View GitHub Profile
from collections import Counter
with open("/usr/share/dict/words") as fh:
solutions = {}
for i, line in enumerate(fh.readlines()):
if i > 100000:
break
w = line.lower().strip()
h = tuple(sorted(Counter(w).elements()))
if h not in solutions:
solutions[h] = set()
@sirpengi
sirpengi / output.txt
Created February 27, 2014 18:40
Look at that O(n)
[sirpengi@localhost tmp]$ python anagrams.py
############# (1.31171178818)
################ (1.60090017319)
################### (1.9009168148)
###################### (2.23292398453)
######################### (2.55905890465)
@sirpengi
sirpengi / question
Last active August 29, 2015 13:57
proggitquiz
"If the integers from 1 to 999,999,999 are written as
words, sorted alphabetically, and concatenated, what
is the 51 billionth letter?"
To be precise: if the integers from 1 to 999,999,999
are expressed in words (omitting spaces, 'and', and
punctuation[1]), and sorted alphabetically so that
the first six integers are
eight
@sirpengi
sirpengi / error.js
Last active August 29, 2015 13:57
roll20 bug
on("ready", function() {
var n = +new Date();
var obj = createObj("rollabletable", {
name: String(n)
});
obj.set("name", "post_" + n);
});
@sirpengi
sirpengi / keybase.md
Created March 31, 2014 06:33
keybase.md

Keybase proof

I hereby claim:

  • I am sirpengi on github.
  • I am sirpengi (https://keybase.io/sirpengi) on keybase.
  • I have a public key whose fingerprint is EF6E FAE9 4D6B CA66 8EA2 4C1F B6BE 3624 D5BC 9DA1

To claim this, I am signing this object:

@sirpengi
sirpengi / output.txt
Last active August 29, 2015 14:01
some sandpile thing
We couldn’t find that file to show.
@sirpengi
sirpengi / hmmm.py
Created July 10, 2014 08:18
looks bad when I outline it like this
if:
if:
if not:
raise
if:
elif:
if not:
raise
if:
elif:
@sirpengi
sirpengi / touch.js
Created July 18, 2014 22:41
emulate touch event
// go to http://patrickhlauke.github.io/touch/tests/event-listener.html
el = document.getElementsByClassName("button")[0];
e = new Event("touch");
e.initEvent("touchstart", true, true);
el.dispatchEvent(e);
@sirpengi
sirpengi / fsm_test.js
Last active August 29, 2015 14:05
sample usage of backbone-fsm
module.paths.push(".");
var assert = require("assert");
var _ = require("underscore");
var Backbone = require("backbone");
var FSM = require("backbone-fsm").BackboneFSM;
/* Implementation of a turnstile (i.e., at train station). Turnstile is
initially locked and won't let people through. Once a coin is
inserted, the turnstile becomes unlocked, and lets one person through before
@sirpengi
sirpengi / lol.js
Created September 4, 2014 22:28
wtf javascript
var assert = require("assert");
assert.equal(
({lol: 'LOL', javascript: 'JAVASCRIPT'})['lol', 'wtf', 'javascript'],
"JAVASCRIPT"
);
assert.equal(
({lol: 'LOL', javascript: 'JAVASCRIPT'})[['javascript']],
"JAVASCRIPT"