Skip to content

Instantly share code, notes, and snippets.

View ziotom78's full-sized avatar

Maurizio Tomasi ziotom78

View GitHub Profile
@ziotom78
ziotom78 / fontforge-install.log
Created June 28, 2011 12:21
Output of "brew install -v fontforge"
==> Downloading http://downloads.sourceforge.net/project/fontforge/fontforge-source/fontforge_full-20110222.tar.bz2
File already downloaded in /Users/tomasi/Library/Caches/Homebrew
/usr/bin/tar xf /Users/tomasi/Library/Caches/Homebrew/fontforge-20110222.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/fontforge/20110222 --enable-double --without-freetype-bytecode
./configure --prefix=/usr/local/Cellar/fontforge/20110222 --enable-double --without-freetype-bytecode
checking for gcc... /usr/bin/cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
@ziotom78
ziotom78 / brew-doctor.log
Created June 28, 2011 12:21
Output of "brew doctor" after failed installation of "fontforge"
Your OS X is ripe for brewing.
Any troubles you may be experiencing are likely purely psychosomatic.
@ziotom78
ziotom78 / problem34.ml
Created September 28, 2011 07:54
Solution for problem 34 in OCaml
let fast_fact =
let rec fact n = if n > 1 then n * fact (n - 1) else 1
in Array.map fact [|0; 1; 2; 3; 4; 5; 6; 7; 8; 9|];;
let digits num =
let rec helper num result =
if num < 10 then num :: result else helper (num / 10) ((num mod 10) :: result)
in helper num [];;
let test_number num =
@ziotom78
ziotom78 / problem34.hs
Created September 28, 2011 09:37
Solution of Project Euler's Problem 34 (Haskell)
import Data.Char (digitToInt)
main = print (sum ([x | x <- [10..100000], x == sum (map (\n -> product [1..n]) (map (digitToInt) (show x)))]))
@ziotom78
ziotom78 / problem34.clj
Created September 28, 2011 10:05
Solution for Project Euler's problem 34 (Clojure)
(defn fact
"Return n!."
[^Integer n]
(if (< n 2)
1
(apply * (range 2 (+ n 1)))))
(def fast-fact
; This is a faster version of "fact", using a dictionary to return the
; factorial for any number between 0 and 9 (the only kind of number for which
@ziotom78
ziotom78 / problem34.py
Created September 28, 2011 10:05
Solution of Project Euler's problem 34 (Python)
def fact (n):
"Return n!."
if n < 2:
return 1
else:
result = 1
for i in xrange (2, n + 1):
result = result * i
return result
@ziotom78
ziotom78 / double.cpp
Created October 14, 2011 20:15
Double a floating-point number (version without reference argument)
double
doubleThis(double x)
{
return x * 2;
}
@ziotom78
ziotom78 / double.s
Created October 14, 2011 20:18
Assembly output of GCC 4.2.1 for the "doubleThis" function
__Z11doubleThisd:
pushq %rbp
movq %rsp, %rbp
movsd %xmm0, -8(%rbp)
movsd -8(%rbp), %xmm0 # Directly copy the parameter into the FP register
addsd %xmm0, %xmm0 # Calculate x+x instead of 2x
leave
ret
@ziotom78
ziotom78 / doubleWithReference.cpp
Created October 14, 2011 20:20
Double a floating-point value (with reference parameter)
double
doubleThis(double & x)
{
return x * 2;
}
@ziotom78
ziotom78 / doubleWithReference.s
Created October 14, 2011 20:25
Assembly code produced by GCC 4.2.1 for the "doubleThis" function (with reference parameter)
__Z24doubleThisRd:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -8(%rbp)
movq -8(%rbp), %rax
movsd (%rax), %xmm0 # Put in xmm0 the value pointed by RAX
addsd %xmm0, %xmm0 # Calculate x+x instead of 2x
leave
ret