Physics for martial arts students

physics_for_martial_arts_students_thumbRight after the kickboxing class, I saw one of classmate and friend of mine trying to solve a physics exercise. I studied physics in high school, and I had a exam in college; it was long time ago and even at that time I wasn’t very strong in the matter (and I used to soothe myself (or to fool myself?) quoting Linus Torvalds “While in physics you’re supposed to figure out how the world is made up, in computer science you create the world.” But that’s a different story), but I decided that I could help, after all it didn’t sound too difficult.

The problem

The problem required finding the final velocity (rounded at one decimal digit), v_f of a ball thrown down from a 40 meters tall tower with a initial velocity, v_0, of 12 m/s. The exercise book was providing also the solution: 30.5 m/s. Read more of this post

Adding a method for computing Cartesian Product to Groovy’s Collection(s)

groovy-cartesian-productIn these days I’m using the Groovy programming language very often, I found this language very intuitive and expressive. I try to use, when it is appropriate and convenient , Functional programming style and methods.

One of the key elements of functional programming paradigm (opposite to the imperative paradigm) is “thinking in  space rather than thinking in time”, this translates in a extensive usage of collections and constructs for creating a collection based on existing collections. The most common collection used is the list, the syntactic construct for creating a list based on existing lists is named List comprehension.

I think that the list, or more generic collection, comprehension in Groovy is very powerful (Groovy Collection API), and in my everyday usage I found that it has everything that I need to express the algorithm that I implement in terms of Collection comprehension. By the way, more that once I needed to obtain the Cartesian product of two collections, so I thought it is nice to have a method in Collection for computing the Cartesian product.

Cartesian product

The Cartesian product is a mathematical operation which returns a set (or product set) from multiple sets. That is, for sets A and B, the Cartesian product A × B is the set of all ordered pairs (a,b) where a ∈ A and b ∈ B:

f(A, B) = \bigcup_{a\in A}\bigcup_{b\in B} (a, b).

Read more of this post