This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; '(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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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)))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use List::Util qw(sum); | |
sub foreachLine { | |
my ($const, $finalize) = @_; | |
while (<DATA>) { | |
$const->($_); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use List::Util qw(sum); | |
my $par = shift; | |
sub foreachLine { | |
my ($const, $finalize) = @_; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use List::Util qw(sum); | |
sub foreachLine { | |
my ($const, $finalize) = @_; | |
while (<DATA>) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) =@_; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 { |