Skip to content

Instantly share code, notes, and snippets.

@flatline
flatline / 8puzzle.py
Created February 22, 2011 04:00
An eight-puzzle solver in python
# Solves a randomized 8-puzzle using A* algorithm with plug-in heuristics
import random
import math
_goal_state = [[1,2,3],
[4,5,6],
[7,8,0]]
def index(item, seq):
//The game of Snake in Scala
package snake
import javax.swing.{JFrame,JPanel,Timer}
import java.awt.Graphics
import java.awt.event.{ActionEvent,ActionListener,KeyListener,KeyEvent}
import scala.actors.Actor
import scala.actors.Actor._
case class Listen(actor: Actor)
#lang scheme
;some quick code for approximating definite integrals
;Trapezoid Rule approximation for the integral of f over range (a,b) in n divisions
(define (area-trap f a b n)
(let ([dx (/ (- b a) n)])
(define (iter x list)
(cond ((= x b)
(iter (- x dx) (cons (f x) list)))
((= x a)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; A simple orrery in clojure. Models a 2-dimensional,
;; orthogonal solar system, with the planets most definitely
;; not to scale.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(ns orrery
(:import [java.awt Color Dimension]
[java.awt.event ActionListener]
[javax.swing JFrame JPanel Timer]))