dimanche 19 mai 2013

Tumblr backup

Exercise in Python and threads. Small script to create Tumblr blog backups. For now it just downloads all photo posts of a given blog (primary reason for this script to appear). Later maybe I will extend it to other types of posts.

https://bitbucket.org/mrklein/tumblr-backup

dimanche 5 mai 2013

Number 123456 again

And prize for the best usage of GMP goes to Bigloo Scheme.

(module fact)
(define *num-list* '(1 12 123 1234 12345 123456))
(define (factorial n)
(define (iter k acc)
(if (= k 1)
acc
(iter (- k 1) (* k acc))))
(iter n 1))
(define (dfactorial n)
(do ((r 1)
(i 1 (+ i 1)))
((= i n) r)
(set! r (* r i))))
(define (sum-digits n)
(reduce + 0 (map
(lambda (c) (- (char->integer c) (char->integer #\0)))
(string->list (number->string n)))))
;; Taken from example of time function in Bigloo reference
(multiple-value-bind (res rtime stime utime)
(time
(lambda ()
(reduce + 0 (map sum-digits (map factorial *num-list*)))))
(print "Recursive factorial: " (* 0.001 rtime) " sec "))
(multiple-value-bind (res rtime stime utime)
(time
(lambda ()
(reduce + 0 (map sum-digits (map dfactorial *num-list*)))))
(print "Iterative factorial: " (* 0.001 rtime) " sec "))
view raw factorial.scm hosted with ❤ by GitHub



alexey at daphne in ~/Projects/tests$ bigloo -O3 fact.scm
ld: warning: option -s is obsolete and being ignored
alexey at daphne in ~/Projects/tests$ ./a.out
Recursive factorial: 4.44 sec
Iterative factorial: 3.96 sec
It has only factor of 2 compared to C version.