Skip to content

Instantly share code, notes, and snippets.

View petertseng's full-sized avatar

Peter Tseng petertseng

View GitHub Profile
@petertseng
petertseng / bfs.js
Created April 21, 2014 10:34
Untrusted maze
if (me.getX() == map.getWidth() - 3 && me.getY() == 8) {
me.move('right');
}
if (me.getX() == map.getWidth() - 2 && me.getY() >= 7 && me.getY() <= 15) {
me.move('down');
}
var seen = {};
var frontier = [];
var moves = map.getAdjacentEmptyCells(me.getX(), me.getY());
@petertseng
petertseng / auth.rb
Created May 30, 2015 05:27
Crappy cinch auth
require 'cinch'
require 'set'
require 'yaml'
# I'm not using this, but we can think about it.
module Cinch; class Authorization
class Group
attr_reader :authnames
@petertseng
petertseng / poker.rb
Last active August 29, 2015 14:25
poker hands in rust and ruby
class Card
attr_reader :rank, :suit
def initialize(rank, suit)
@rank = rank
@suit = suit
end
def to_s
"#{@rank} of #{@suit}"
end
@petertseng
petertseng / splendordata.java
Created September 8, 2015 08:10
splendordata
// points, red, green, blue, white, black
protected final static Card[] cardsNormal = new Card[]{
// 3 pointer: 5 of self+2, 3 of every other color except self
// 4 pointer single: 7 of self+1
// 4 pointer multi: 6 of self+1, 3 of self, 3 of self+2
// 5 pointer: 7 of self+1, 3 of self
new Card(CardLevel.THREE, TokenColor.BLACK, 3, 3, 5, 3, 3, 0),
new Card(CardLevel.THREE, TokenColor.BLACK, 4, 6, 3, 0, 0, 3),
new Card(CardLevel.THREE, TokenColor.BLACK, 4, 7, 0, 0, 0, 0),
@petertseng
petertseng / output
Last active November 1, 2015 18:07
Upside down words!
dod -> pop
dollop -> dollop
dot -> top
dots -> stop
loot -> tool
loots -> stool
los -> sol
nu -> nu
otto -> otto
plot -> told
@petertseng
petertseng / whosonfirst-quiz.rb
Last active November 29, 2015 02:41
Who's on first?
MAPPINGS = {
#?A
?B => "BLANK",
#?C
?D => "DONE",
?E => "LIKE",
?F => "FIRST",
#?G
?H => "HOLD",
#?I
@petertseng
petertseng / 161201.txt
Last active March 5, 2018 11:22
Advent of Code language counts
#Total at 161201 2696
Python 638
Javascript 270
Java 206
Ruby 206
C# 158
Haskell 116
Go 101
C++ 86
PHP 85
module FlowerPuzzle
refine Array do
def to_i
reduce(0) { |acc, e| acc * 3 + e }
end
def apply_move(move)
zip(move).map { |a, b| (a + b) % 3 }
end
end
@petertseng
petertseng / lib.rs
Last active August 17, 2016 07:16
space age - macros and Age<T>
use std::marker::PhantomData;
macro_rules! planet {
($planet: ident, $planetage: ident, $period: expr) => {
pub struct $planet;
impl Planet for $planet { fn period() -> f32 { $period } }
pub type $planetage = Age<$planet>;
};
}
@petertseng
petertseng / advent-of-code-width70.txt
Last active December 10, 2016 02:50
Advent of code day 8 instructions
rect 70x2
rotate column x=69 by 3
rotate row y=3 by 1
rotate column x=68 by 2
rotate column x=67 by 5
rotate column x=66 by 5
rotate row y=5 by 69
rotate column x=64 by 5
rotate row y=2 by 66
rotate column x=63 by 1