Skip to content

Instantly share code, notes, and snippets.

@sathish316
sathish316 / alphametric_solver.rb
Created September 18, 2012 16:08
Alphametric solver golf
s=->(e){c=e.scan(/\w/).uniq;('0'..'9').to_a.permutation(c.size).each{|p|o=c.zip(p).inject(e){|e,d|e.gsub(*d)};p o if o !~/\b0/&&eval(o)}}
s.("SEND + MORE == MONEY")
def show
@results = Foo.all
respond_to do |format|
format.csv { render_csv "report"}
end
end
private
def render_csv(filename = nil)
@sathish316
sathish316 / golbits.rb
Created May 17, 2012 17:05
Game of life bit twiddling
=begin
........ 0x00
........ 0x00
..XX.... 0x30
..XX.... 0x30
....XX.. 0xC0
....XX.. 0xC0
........ 0x00
........ 0x00
=end
@sathish316
sathish316 / gol.rb
Created February 9, 2012 17:04
Game of life golf
d=[-1,0,1] n=->(w,i,j){(d.product(d)-[[0,0]]).map{|x,y|w[[i+x,j+y]]}.count(true)} t=->(w){Hash[w.map{|k,v|c=n.(w,*k);[k,(v&&c==2)||c==3]}]}
@sathish316
sathish316 / alphametric_solver.rb
Created January 29, 2012 18:58
Alphametric solver for equations like SEND + MORE = MONEY (Golf version)
def s(e)
c=e.scan(/\w{1}/).uniq
d=('0'..'9').to_a
d.permutation(c.size).each{|p|o=c.zip(p).inject(e){|e,d|e.gsub(*d)};return o if o !~/\b0/ && eval(o)}
end
puts s("SEND + MORE == MONEY")
@sathish316
sathish316 / ycombinator.ss
Created January 23, 2012 17:58
Y combinator (Little Schemer)
; function to find the length of a list
(define length
(lambda (l)
(cond
((null? l) 0)
(else (+ 1 (length (cdr l)))))))
; function that recurs infinitely
(define eternity
(lambda (l)
@sathish316
sathish316 / ai-class.py
Created December 7, 2011 11:44 — forked from sumodx/ai-class.py
Download lecture videos of ai-class, with basic resume support
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = "Deepak.G.R."
__credits__ = "Sumod Hajela"
__license__ = 'Public Domain'
"""
usage:
Go to command line and type
@sathish316
sathish316 / .gitconfig
Created September 22, 2011 13:54
gitconfig file
[alias]
st = status
ci = commit
br = branch
co = checkout
df = diff
lg = log -p
rpull = pull --rebase
[user]
name = Sathish
emacs shortcuts
C-x C-c quit
C-v next screen
M-v previous screen
C-l move cursor to center
C-f forward char
C-b backward char
C-p previous line
C-n next line
@sathish316
sathish316 / gist:722109
Created November 30, 2010 18:17
cadr.rb
class Array
def car
first
end
def cdr
self[1..-1]
end
def method_missing(method_id)