Karachi   ->   Sweden   ->   Karachi, again   ->   Dubai   ->   Bahrain   ->   Karachi, once more   ->   London and Leeds

Sunday, October 19, 2008

TRG Tech Mind Games

TRG Tech sometimes posts a "crack this code" challenge along with their job ads in local newspapers. This month the challenge is to tell what the following code does:

z = lambda n:{ x for x in range (2, n+1) if len ([ i for i in range (2, x) if x%i == 0 ]) == 0 }

I am not sure what functional language this is written in but it seems to be definition of a function which returns a set of prime numbers below the given number. However, I think there is a bug as well (not sure about the language, so I can't be 100% confident). The check in the list should be as following, in my opinion:

[i for i in range (2, x-1) if x%i == 0]