Skip to content

Instantly share code, notes, and snippets.

@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)
@sathish316
sathish316 / guess_my_number
Created November 29, 2010 21:41
Binary search guessing game from Land of Lisp book
(defparameter *small* 1)
(defparameter *big* 100)
(defun guess-my-number ()
(ash (+ *small* *big*) -1))
(defun smaller ()
(setf *big* (1- (guess-my-number)))
(guess-my-number))
@sathish316
sathish316 / oneplus.scala
Last active September 20, 2015 12:39
Generate email ids for oneplus registration based on an amazon review (http://www.amazon.in/review/REA7WFX7PV3KO)
object OnePlus {
def main(args: Array[String]) {
generate_aliases("typeyouremailhere@gmail.com").foreach(println)
}
def generate_aliases(email:String) = {
val email_pattern = """(\w+)@([\w\.]+)""".r
email match {
case email_pattern(address, domain) => {
interleave_all_with(address, '.').map {case address => s"$address@$domain"}
@sathish316
sathish316 / snakes_and_ladders.ex
Last active September 14, 2015 10:05
Snakes and Ladder - Elixir Game server
defmodule GameServer do
use GenServer
def start do
initial_state = {:players, [], :positions, Map.new, :snakes_and_ladders, [
{:ladder, 5, 15}, {:ladder, 10, 22}, {:ladder, 25, 45}, {:snake, 35, 15}, {:snake, 65, 55}]}
GenServer.start_link(__MODULE__, initial_state, name: __MODULE__)
end
def join(player), do: GenServer.cast(__MODULE__, {:join, player})