Skip to content

Instantly share code, notes, and snippets.

View bhugueney's full-sized avatar

bhugueney

View GitHub Profile
(defn fibonacci [n]
(letfn [(power-accumulate-positive [r a n op]
(let [r (if (odd? n) (op r a) r)]
( if (= 1 n) r (recur r (op a a) (bigint (/ n 2)) op))))
(power [a n op]
(if (odd? n)
(let [n (bigint (/ n 2))]
(if (zero? n) a (power-accumulate-positive a (op a a) n op)))
(recur (op a a) (bigint (/ n 2)) op)))
(fibonacci-matrix-multiply [[x0 x1] [y0 y1]]
@bhugueney
bhugueney / Algorithmic-Complexity-Intro.org
Created June 18, 2015 23:51
org-mode teaching material for introduction to algorithmic complexity

Algorithmic Complexity

#!/usr/bin/env bash
[ $# -ge 1 -a -f "$1" ] && input="$1" || input="-"
wget -q "http://mary.dfki.de:59125/process?INPUT_TYPE=TEXT&OUTPUT_TYPE=AUDIO&INPUT_TEXT="$(cat ${input} | od -An -tx1 | tr ' ' % | xargs printf "%s")"&OUTPUT_TEXT=&effect_Volume_selected=&effect_Volume_parameters=amount%3A2.0%3B&effect_Volume_default=Default&effect_Volume_help=Help&effect_TractScaler_selected=&effect_TractScaler_parameters=amount%3A1.5%3B&effect_TractScaler_default=Default&effect_TractScaler_help=Help&effect_F0Scale_selected=&effect_F0Scale_parameters=f0Scale%3A2.0%3B&effect_F0Scale_default=Default&effect_F0Scale_help=Help&effect_F0Add_selected=&effect_F0Add_parameters=f0Add%3A50.0%3B&effect_F0Add_default=Default&effect_F0Add_help=Help&effect_Rate_selected=&effect_Rate_parameters=durScale%3A1.5%3B&effect_Rate_default=Default&effect_Rate_help=Help&effect_Robot_selected=&effect_Robot_parameters=amount%3A100.0%3B&effect_Robot_default=Default&effect_Robot_help=Help&effect_Whisper_selected=&effect_Whisper_parameters=amount%3A10
@bhugueney
bhugueney / core.clj
Last active October 11, 2016 18:03
interpreter and compiler for arithmetic integer expressions with instaparse and ASM
(ns interpret.core
(:require [instaparse.core :as insta])
(:import (clojure.asm Opcodes Type ClassWriter)
(clojure.asm.commons Method GeneratorAdapter)) )
(def parser-arith
(insta/parser
"<expr> = spaces add-sub spaces
<add-sub> = mul-div | add | sub
add = add-sub spaces <'+'> spaces mul-div
import turtle
import math
import random
import sys
# point is (x,y,z) float cooords
# polygon is ([points], color) is oriented for vector product to know if facing
# object is [polygons] is convex (cf. orientation)
# rotating_object is (object, (a,(u,v,w)) angle and axis of rotation (center of rotation is barycenter of object)
# figure is [rotating_objects]
import math
import turtle
def rotate(a, v):
(x, y)= v
return (math.cos(a)*x - math.sin(a)*y, math.sin(a)*x + math.cos(a)*y)
def demo0(n):
angle_step= 2*math.pi/n
p= (0,100)
@bhugueney
bhugueney / loco_example.clj
Created April 14, 2016 15:28
arithmetic constraints puzzle with Clojure / Loco
;; cf https://github.com/aengelberg/loco/blob/master/test/loco/integer/sendmoremoney1.clj
(ns constrained-grouping.core
(:use loco.constraints
loco.core))
(defn initialize-digits [vars]
(for [v vars]
($in v 0 9)))
(def letters
(ns physics-demos.fractals
(:require
[thi.ng.geom.core :as g]
[thi.ng.geom.core.vector :as v :refer [vec2 vec3]]
[thi.ng.geom.core.matrix :as mat :refer [M32 M44]]
[thi.ng.geom.circle :as c]
[thi.ng.geom.spatialtree :as accel]
[thi.ng.geom.svg.core :as svg]
[thi.ng.geom.physics.core :as phys]
[thi.ng.geom.webgl.animator :refer [animate]]
@bhugueney
bhugueney / Test-org-reveal-Klipse.org
Created September 11, 2016 14:21
Trying to use Klipse in org reveal

Trying to use Klipse

With code tag

test

@bhugueney
bhugueney / GoGUI.java
Created January 24, 2017 13:37
minimal Goban
public class GoGUI {
final static int SIZE= 8;
final static double EMPTY_RADIUS=0.1;
final static double STONE_RADIUS=0.45;
final static String PASS_STRING= "PASS";
final static int PASS_X=0;
public static void main(String args[]){
StdDraw.setXscale(-1, SIZE);
StdDraw.setYscale(-1, SIZE);