Skip to content

Instantly share code, notes, and snippets.

def find_median_sorted arr1, arr2
joined = (arr1 + arr2).sort
if joined.size % 2 == 0
return joined[(joined.size/2)-1..(joined.size/2)].reduce(&:+) / 2.0
else
return joined[joined.size/2]
end
end
@dustMason
dustMason / keybase.md
Created August 4, 2017 22:09
keybase.md

Keybase proof

I hereby claim:

  • I am dustmason on github.
  • I am dustmason (https://keybase.io/dustmason) on keybase.
  • I have a public key ASCHhKGcG3EAzzZ3-nz6OEC2IxecrY77ntKiusv920L8lwo

To claim this, I am signing this object:

require 'io/console'
class TicTacToe
attr_reader :state
def initialize *players
@players = players
@state = players.map { Array.new(9) }
@marks = ['X','O']
def optimal_move state
return state if Math.sqrt(state) % 1 == 0 # its a perfect square
(1..Math.sqrt(state)).each { |n| return n*n if optimal_move(state - (n*n)) == -1 }
return -1
end
https://gist.github.com/dustMason/487eabfa2cafd2e2b0c4814903c21772
require 'io/console'
class Game
attr_reader :playing
def initialize
@width = 50
@height = 30
@snake = []
@score = 0
require 'io/console'
class Game
attr_reader :playing
def initialize
@width = 50
@height = 30
@board = [].tap { |s| @width.times { |x| @height.times { |y| s << [x, y] } } }
@snake = []
Sarah, Alice, John, Bob
Sarah -400
---
Sarah -300
Alice 100
John 100
Bob 100
John -100
@dustMason
dustMason / svgreader.js
Last active October 3, 2018 05:40
SVG Tools
/**
SVG parser for the Lasersaur.
Converts SVG DOM to a flat collection of paths.
Copyright (c) 2011 Nortd Labs
Open Source by the terms of the Gnu Public License (GPL3) or higher.
Code inspired by cake.js, canvg.js, svg2obj.py, and Squirtle.
Thank you for open sourcing your work!
@dustMason
dustMason / makefile
Created December 7, 2018 06:29
Makefail
.PHONY .NOTPARALLEL : B K F I T U R Z N S X Y L J G W A H Q M P V O D E C
A : W
@echo "A"
A : U
@echo "A"
A : J
@echo "A"