mercoledì 22 settembre 2010

Socks' like software

When you don't sew a little hole, you'll have to sew a big one

Such a worldly wisdom perfectly match both software and socks.

Se non cuci un buchino, dovrai cucire un bucone.

Saggezza popolare perfettamente applicabile al software come ai calzini.

Leadership and Responsibility

The word "responsibility" derive, in it's etymology, from "responsum abilem" that means "able to answer for".

Leadership and responsibility are deeply interconnected: a leader should be able to answer and explain the reasons of it's own decision to anyone that ask about them.

From such ability derive the confidence that both the team and the team's stakeholders give to the leader. Confidence that should be "signed" form his "authority", his position in the enterprise organization.

But authority without responsibility lead to decision deadlock, since the fear to respond rapidly cause the fear to take decisions.

Leaders that are not able to answer for their decision can not lead.

People that rely on their position in the organization (their authority) to endorse their decisions should be replaced.

martedì 21 settembre 2010

First mobile application deployed

I've just deployed the SGADataCollector to my wife's phone.

It was easy, thanks to my N95 and X-plore.

It has been quite pleasant to see it working, since it's a quick & dirty application built in less than a week.

martedì 7 settembre 2010

Problem 3

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

import Data.List

solution = head $ reverse $ factors 600851475143

factors :: Integral a => a -> [a]
factors x = unfoldr nextFactor (x, primes)
    where nextFactor (1, _) = Nothing
          nextFactor (x, p:ps)
            | mod x p == 0 = Just (p, (divAll x p, ps))
            | otherwise = nextFactor (x, ps)
          divAll x factor
            | mod x factor == 0 = divAll (div x factor) factor
            | otherwise = x

primes :: Integral a => [a]
primes = 2 : iterate nextPrime 3
    where nextPrime x = head $ filter isPrime[(x+1)..] 

isPrime :: Integral a => a -> Bool
isPrime x = and $ [mod x p /= 0 | p <- takeWhile lowerThanSqrtX primes]
    where lowerThanSqrtX candidate = candidate <= (round $ sqrt $ fromIntegral x)




To be improved in the future...

domenica 5 settembre 2010

Problem 2

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Find the sum of all the even-valued terms in the sequence which do not exceed four million.

solution = sum $ filter even $ fibsLowerThan 4000000

fibsLowerThan upperBound = fibs 0 upperBound 

fibs :: Integral a ⇒ a → a → [a]
fibs n upperBound
| fib n > upperBound = []
| otherwise = fib n : fibs (n + 1) upperBound

fib 0 = 0
fib 1 = 1
fib n = sum [fib $ n - 1, fib $ n - 2]




Too much time to write it right... wtf...

Problem 1

Problem 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

solution = sum $ [x | x ←  [1..999], or [mod x 3 ≡ 0, mod x 5 ≡ 0]]