Skip to content

Instantly share code, notes, and snippets.

View petertseng's full-sized avatar

Peter Tseng petertseng

View GitHub Profile
@petertseng
petertseng / md515.cr
Last active December 27, 2016 08:19
day 15 with extra hash powers
require "crypto/md5"
hash = "0" * 32
zeroes = Array.new(32, 1)
ROWS = 8
almost = 0
hashes = Array.new(ROWS, "")
hashes[0] = hash
@petertseng
petertseng / 123
Last active December 26, 2016 23:49
day11inputs
The first floor contains a 1 generator, a 2 generator, a 3 generator, a 4 generator, a 5 generator, a 6 generator, a 7 generator, a 8 generator, a 9 generator, a 10 generator, a 11 generator, a 1-compatible microchip, a 2-compatible microchip, a 3-compatible microchip, a 4-compatible microchip, a 5-compatible microchip, a 6-compatible microchip, a 7-compatible microchip, a 8-compatible microchip, a 9-compatible microchip, a 10-compatible microchip, and a 11-compatible microchip.
The second floor contains nothing relevant.
The third floor contains nothing relevant.
The fourth floor contains nothing relevant.
@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
@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>;
};
}
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 / 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
@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 / 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 / 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 / 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