Skip to content

Instantly share code, notes, and snippets.

;; '(0 0 1 0 0) => ((2 0) 1 (2 0))
;; CL-USER> (compress '(3 3 4 3 3 2 1 1 1 1 0))
;; ((2 3) 4 (2 3) 2 (4 1) 0)
(defun compress (l1)
(cond ((null (cdr l1)) '())
(t (accum (car l1) 1 (cdr l1)))))
(defun accum (val acc lst)
(cond ((null lst) (cons (comp-list val acc) nil))
(defun bin-search (obj vect)
(bin-search-rec obj vect 0 (1- (length vect))))
(defun bin-search-rec (obj vec start end)
(let* ((range (- end start))
(mid (+ start (round (/ range 2)))))
(cond ((eq (aref vec mid) obj) (format t "l'hem trobat a la posicio blabla ~A" mid))
((zerop range) nil)
((< (aref vec mid) obj) (bin-search-rec obj vec (1+ mid) end))
((> (aref vec mid) obj) (bin-search-rec obj vec start (1- mid))))))
@kidd
kidd / .emacs
Created January 10, 2010 16:35
(defun mouse-avoidance-banish-destination ()
"The position to which Mouse-Avoidance mode `banish' moves the mouse.
You can redefine this if you want the mouse banished to a different corner."
(let* ((pos (window-edges)))
(cons (- (nth 2 pos) 2)
(+ (nth 1 pos) 1))))
;;; permutations with repetitions. Base to get all possible
;;; mastermind solutions.
;;;
;;; Example usage:
;;; (perm '(1 2 3) 2) => ((1 1) (2 1) (3 1) (1 2) (2 2) (3 2) (1 3) (2 3) (3 3))
(define (perm lst len)
(cond ((= 0 len) '(()))
(else (append-map (lambda (x)
(map (lambda (y) (cons y x )) lst))
(perm lst (- len 1))))))
#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(sum);
sub foreachLine {
my ($const, $finalize) = @_;
while (<DATA>) {
$const->($_);
#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(sum);
my $par = shift;
sub foreachLine {
my ($const, $finalize) = @_;
#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(sum);
sub foreachLine {
my ($const, $finalize) = @_;
while (<DATA>) {
#lang scheme
;;; Helpers
;;; Utility to sum a list
(define (sum l) (foldl + 0 l))
;;; given a hash and a boolean binary function returns the pair which
;;; value is the most 'fun
(define (most-hash h fun)
@kidd
kidd / il.pl
Created February 4, 2010 15:33
#!/usr/bin/perl
use strict;
use warnings;
use HTML::TreeBuilder;
use LWP::UserAgent;
use Data::Dump qw(ddx dump);
sub getShippingRate {
#http://www.iberlibro.com/servlet/ShipRates?vid=51947087
my ($id) =@_;
@kidd
kidd / il.pl
Created February 5, 2010 06:27
#!/usr/bin/perl
use strict;
use warnings;
use HTML::TreeBuilder;
use LWP::UserAgent;
use Data::Dump qw(ddx dump);
use Memoize;
use feature ':5.10';
sub getShippingRate {